#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdbool.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <errno.h>

#include "type.h"
#include "msgcmn.h"
#include "apis.h"
#include "buf_misc.h"
#include "xml_conf.h"
#include "device.h"
#include "cli_main.h"

static I32 queue_rx = 0;
static I32 queue_tx = 0;
static pthread_t dev_rcv_thread;
static U16 cmd_index = 0;
static I32 dev_init_status = DEV_INIT_STAT_DISCONNECT;
static I32 dev_sync_conf = DEV_SYNC_CONF_DONE;
//static I32 cell_status[6] = {0, 0, 0, 0, 0, 0};
//special control, need send 2 commands for pa0 and pa1.

#define DEV_PA0_CONFIGURED	0x10
#define DEV_PA1_CONFIGURED	0x20
//static I32 dev_pa_config = DEV_PA1_CONFIGURED;

//errors
static I8 *sniffer_busy = "Sniffer module busy!";
static I8 *sniffer_empty = "No neighbor cell sniffered!";
static I8 *gsm_inactive = "LTE module is inactive";
static I8 *gnrc_par_error = "Parameter error";
static I8 *pa_not_found = "PA not found";
static I8 *pa_inactive = "PA is inactive";
//warnings
static I8 *warn_pa_over_pwr = "PA is over power";
static I8 *warn_pa_over_tmp = "PA is over temperature";
static I8 *warn_pa_swr = "VSWR warning";
static I8 *warn_pa_fault = "PA fault";
static I8 *warn_gsm_fault = "LTE board fault";
static I8 *warn_gsm_resume = "LTE board resumed";
static I8 *warn_dev_door = "device box open";
static I8 *warn_dev_grand_lost = "device line break";
static I8 *warn_download_failed = "download_failed";
static I8 *warn_md5sum_mismatch = "md5sum_mismatch";
static I8 *warn_noclean = "upgarade in progress";
static I8 *warn_decompross_failed = "pkg_decompress_failed";
static I8 *warn_write_kernel_failed = "write_kernel_failed";
static I8 *warn_write_rootfs_failed = "write_rootfs_failed";
static I8 *warn_write_x86app_failed = "write_x86app_failed";


static I8 *tdd_img = "lte_tddzm.img";
static I8 *fdd_img = "lte_fddzm.img";
static I8 *tdd_md5 = "/tftpboot/lte_tddzm.img.md5sum";
static I8 *fdd_md5 = "/tftpboot/lte_fddzm.img.md5sum";

extern I8 *srvcmd;
char ssh_state = '0';

#define  allModuleIintNum 42
I32 allModuleInit[allModuleIintNum] = 
{
    REQUEST_REDIRECT_INIT_CONFIG,
    REQUEST_UPDATA_SMS,  
    REQUEST_UPDATA_STORAGE,
    REQUEST_UPDATA_SMS_MSG,
    REQUEST_UPDATA_SMS_KEY,
    REQUEST_UPDATA_SYS_RBEOOT,
    REQUEST_SET_UPLOAD_MODE,
    REQUEST_SET_VAILD_PA,
    REQUEST_SET_LOCATION_MODE,
    REQUEST_BBU1_INIT_CONFIG,
    REQUEST_BBU2_INIT_CONFIG,
    REQUEST_BBU3_INIT_CONFIG,
    REQUEST_BBU4_INIT_CONFIG,
    REQUEST_BBU5_INIT_CONFIG,
    REQUEST_BBU6_INIT_CONFIG,
    REQUEST_BBU7_INIT_CONFIG,
    REQUEST_BBU_TX_POWER1,
    REQUEST_BBU_TX_POWER2,
    REQUEST_BBU_TX_POWER3,
    REQUEST_BBU_TX_POWER4,
    REQUEST_BBU_TX_POWER5,
    REQUEST_BBU_TX_POWER6,
    REQUEST_BBU_TX_POWER7,
    REQUEST_BBU1_RSSI_CONFIG,
    REQUEST_BBU2_RSSI_CONFIG,
    REQUEST_BBU3_RSSI_CONFIG,
    REQUEST_BBU4_RSSI_CONFIG,
    REQUEST_BBU5_RSSI_CONFIG,
    REQUEST_BBU6_RSSI_CONFIG,
    REQUEST_BBU7_RSSI_CONFIG,
    REQUEST_UPDATA_GSM1,
    REQUEST_UPDATA_GSM2,
    REQUEST_UPDATA_GSM_ENABLE,
    REQUEST_UPDATA_GSM_SNIFER,
    REQUEST_UPDATA_GSM_SNIFER_PAR,
    REQUEST_UPDATA_GSM_REDET,
    REQUEST_GSM_MANUAL_SNIFFER,
    REQUEST_UPDATA_CDMA,
    REQUEST_UPDATA_CDMA_WIFI,
    REQUEST_UPDATA_WCDMA,
    REQUEST_UPDATA_TDSCDMA,
    REQUEST_UPDATA_WIFI_CFG
};

enum SyncStaeCode
{
    TAG_REQUEST_REDIRECT_INIT_CONFIG = 0,
    TAG_REQUEST_UPDATA_SMS,
    TAG_REQUEST_UPDATA_STORAGE,
    TAG_REQUEST_UPDATA_SMS_MSG,
    TAG_REQUEST_UPDATA_SMS_KEY,
    TAG_REQUEST_UPDATA_SYS_RBEOOT,
    TAG_REQUEST_SET_UPLOAD_MODE,
    TAG_REQUEST_SET_VAILD_PA,
    TAG_REQUEST_SET_LOCATION_MODE,
    TAG_REQUEST_BBU1_INIT_CONFIG,
    TAG_REQUEST_BBU2_INIT_CONFIG,
    TAG_REQUEST_BBU3_INIT_CONFIG,
    TAG_REQUEST_BBU4_INIT_CONFIG,
    TAG_REQUEST_BBU5_INIT_CONFIG,
    TAG_REQUEST_BBU6_INIT_CONFIG,
    TAG_REQUEST_BBU7_INIT_CONFIG,
    TAG_REQUEST_BBU_TX_POWER1,
    TAG_REQUEST_BBU_TX_POWER2,
    TAG_REQUEST_BBU_TX_POWER3,
    TAG_REQUEST_BBU_TX_POWER4,
    TAG_REQUEST_BBU_TX_POWER5,
    TAG_REQUEST_BBU_TX_POWER6,
    TAG_REQUEST_BBU_TX_POWER7,
    TAG_REQUEST_BBU1_RSSI_CONFIG,
    TAG_REQUEST_BBU2_RSSI_CONFIG,
    TAG_REQUEST_BBU3_RSSI_CONFIG,
    TAG_REQUEST_BBU4_RSSI_CONFIG,
    TAG_REQUEST_BBU5_RSSI_CONFIG,
    TAG_REQUEST_BBU6_RSSI_CONFIG,
    TAG_REQUEST_BBU7_RSSI_CONFIG,
    TAG_REQUEST_UPDATA_GSM1,
    TAG_REQUEST_UPDATA_GSM2,
    TAG_REQUEST_UPDATA_GSM_ENABLE,
    TAG_REQUEST_UPDATA_GSM_SNIFER,
    TAG_REQUEST_UPDATA_GSM_SNIFER_PAR,
    TAG_REQUEST_UPDATA_GSM_REDET,
    TAG_REQUEST_GSM_MANUAL_SNIFFER,
    TAG_REQUEST_UPDATA_CDMA,
    TAG_REQUEST_UPDATA_CDMA_WIFI,
    TAG_REQUEST_UPDATA_WCDMA,
    TAG_REQUEST_UPDATA_TDSCDMA,
    TAG_REQUEST_UPDATA_WIFI_CFG,
    TAG_REQUEST_UPDATA_DONE
};
#ifdef MODULE_TEST
static bool testMsgRcv = false;
void setTestMsgrcv()
{
    testMsgRcv = true;
}

#endif
static bool devThreadIsOk = false;
pthread_mutex_t mutex;

void setMsgRcvThreadOk()
{
    pthread_mutex_lock(&mutex);
    devThreadIsOk = true;
    pthread_mutex_unlock(&mutex);
}

bool GetMsgRcvThreadStat()
{
    bool alive = false;
    pthread_mutex_lock(&mutex);
    alive = devThreadIsOk;
    devThreadIsOk = false;
    pthread_mutex_unlock(&mutex);
    return alive;
}



static I32 parapackU16(PARAM *tlv , U32 paraType, I32 num, U16 *paraValue)
{
    I32 i = 0;
    U16 *pv = (U16 *)(tlv->paraValue);
    tlv->paraType = paraType;
    tlv->paraLength =sizeof(U16) * num;
    for (; i < num; i++)
    {
       *pv = paraValue[i];
        pv++;
    }
    return roundup8( sizeof(PARAM) + tlv->paraLength);

}

static I32 parapackU8(PARAM *tlv , U32 paraType, S8 paraValue)
{
   
    tlv->paraType = paraType;
    tlv->paraLength =  sizeof(U8);
    *(S8 *)tlv->paraValue = paraValue;

    return roundup8( sizeof(PARAM) + tlv->paraLength);     
}

static I32 parapackV8(PARAM *tlv , U32 paraType, I32 num, void *paraValue, size_t size)
{
    tlv->paraType = paraType;
    tlv->paraLength = size * num;
    memcpy((tlv->paraValue), paraValue, tlv->paraLength);

    return roundup8( sizeof(PARAM) + tlv->paraLength);
}

static I32 parapackI8(PARAM *tlv , U32 paraType, I8 * paraValue)
{
   
    tlv->paraType = paraType;
    tlv->paraLength =  strlen(paraValue);
    memcpy((I8 *)(tlv->paraValue), paraValue, strlen(paraValue));

    return roundup8( sizeof(PARAM) + tlv->paraLength);     
}

static I32 parapackU32(PARAM *tlv , U32 paraType, U32 paraValue)
{
    tlv->paraType = paraType;
    tlv->paraLength =sizeof(U32);
    *(U32 *)(tlv->paraValue) = paraValue;
    return roundup8( sizeof(PARAM) + tlv->paraLength);
}



static I32 device_send_msg(DEV_MSG * msg)
{
#if 0
#ifdef IF_APP_UNIT_TEST
    int i, len;
    U16 *tmp = (U16 *) msg;
    I8 *buf;
    len = msg->cmd.cmdLength + DEV_HDR_SIZE + 4;
    printf("Unit test: send msg to device:\n");
    for (i = 0; i < len / 2; i++)
        printf("%04x ", tmp[i]);
    printf("\n");
    buf = buffer_allocate();
    if (buf == NULL) {
        printf("Unit test: Error to allocate buffer\n");
        return -1;
    } else {
        cmd_cmd_code = msg->cmd.cmdCode;

        if (msg->cmd.cmdIndex % 2)
            len = device_gen_result(buf, 1);
        else
            len = device_gen_result(buf, 0);
        if (dev_init_status != DEV_INIT_STAT_DONE)
            event_queue_add(IF_APP_EVENT_INIT_DEV, 0, len, buf);
        else
            event_queue_add(IF_APP_EVENT_DEVICE, 0, len, buf);

    }
    return 0;
#endif
#endif

    msg->hdr.mType = get_mtype(msg->hdr.dstID);
    msg->hdr.srcID = MODULE_INTF;
    msg->hdr.msgType = MSG_TYPE_COMMAND;
    msg->hdr.msgLength = DEV_HDR_SIZE + msg->cmd.cmdLength;

    cli_app_log(CLI_LOG_DEFAULT, 
	    "===============send device msg   to dst=0x%04X len=%d==========>>>>>\n", 
        msg->hdr.dstID, msg->hdr.msgLength);

      buffer_dump_log((I8*)msg, msg->hdr.msgLength, CLI_LOG_DEFAULT);

    if (msgsnd(queue_tx, msg, msg->hdr.msgLength, 0) < 0) {
        cli_app_log(CLI_LOG_CRITICAL, "dev_send_msg error.\n");
        return -1;
    }
    return 0;
}

static I32 device_handle_internal_heartbeat(U32 value, I8* buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_SYSMONITOR;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = CMD_EVENT;
    cmd->cmdCode = CMD_CODE_SYSMONITOR_HEARTBEAT;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    len = parapackU32(tlv, PARA_TYPE_SYSMONITOR_MODULE_STATE, value);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;   
}

static I32 device_handle_smsEn_request(I32 type, I32 code, I32 workMode, I8 * buf,
                                       I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 len = 0;
    I8 *ptr = NULL;
    I32 tmp = (I32) cmd_index;

    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_INFO, "set sms work mode is %d \n", workMode);
    msg->hdr.dstID = MODULE_SMS;	
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    if (type == DEV_OPCODE_SET) {
        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = 0;
        if (code) {
            cmd->cmdCode = CMD_CODE_SMS_ON;
        } else {
            cmd->cmdCode = CMD_CODE_SMS_OFF;
        }
        ptr = (I8 *)(cmd->data);
        PARAM *tlv = (PARAM *)ptr;
        len = parapackU32(tlv, PARA_TYPE_3G_WORKMODE, workMode);
        cmd->cmdLength = len;
    } else if (type == DEV_OPCODE_GET) {
        cmd->cmdType = DEV_OPCODE_GET;
        cmd->cmdCode = CMD_CODE_GET_SMS_STATE;
        cmd->cmdLength = 4 * sizeof(U32);
        cmd->data[0] = PARA_TYPE_3G_SMS_STATE;
        cmd->data[1] = 1 * sizeof(U32);
        cmd->data[2] = 0;
        cmd->data[3] = TLV_PADDING;
    } else {
        return -1;
    }
    *dcode = cmd->cmdCode;

    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_set_upload_mode(I32 type, I32 code, I8 * buf,
                                       I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_DATAPRO;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = CMD_SET;
    cmd->cmdCode = CMD_CODE_SET_UPLOAD_MODE;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    len = parapackU32(tlv, PARA_TYPE_DATAPROC_UPLOAD_MODE , code);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;  

}


static I32 device_handle_set_sys_reboot(I32 type, RESTART_INFO restart, I8 * buf,
                                       I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	I8 *ptr= NULL;
    I32 len = 0, offset = 0;

    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_SYSTEM;	
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    if (type == DEV_OPCODE_SET) {
        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = 0;
        if (atoi(restart.enable)) {
            cmd->cmdCode = CMD_CODE_SYS_REBOOT_ON;
            ptr = (I8 *)(cmd->data);
            PARAM *tlv = (PARAM *)ptr;
            offset =  parapackU32(tlv, PARA_TYPE_SYS_REBOOT_HOUR, atoi(restart.hour));
            ptr += offset;
            len += offset;
            tlv = (PARAM *)ptr;
            offset =  parapackU32(tlv, PARA_TYPE_SYS_REBOOT_MINUTE, atoi(restart.min));
            ptr += offset;
            len += offset;
            cmd->cmdLength = len;
            cli_app_log(CLI_LOG_NOTICE, "set reboot hour is %d min is %d \n", atoi(restart.hour), atoi(restart.min));

        } else {
            cmd->cmdCode = CMD_CODE_SYS_REBOOT_OFF;
        }
    }
    *dcode = cmd->cmdCode;

    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_reboot_request(I32 delay, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_SYSTEM;	
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_SYS_REBOOT;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 4 * sizeof(U32);   //tlv
    cmd->data[0] = PARA_TYPE_DELAY;
    cmd->data[1] = 1 * sizeof(U32);
    cmd->data[2] = delay;
    cmd->data[3] = TLV_PADDING;
    *dcode = cmd->cmdCode;
    if(device_send_msg(msg) < 0)
	{
		cli_app_log(CLI_LOG_ERROR, "send reboot msg failed. \n");
	
        //wait 5 second for logserver to log this message.
		sleep(5);
        //since reboot message sent failure, just reboot here
        system("reboot -f");	
	}
	
    return tmp;
}
static I32 device_handle_time_sync_request(I32 time_sec, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
		
    if (msg == NULL) {
        return -1;
    }
    msg->hdr.dstID = MODULE_SYSTEM;	
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_SYS_TIME_SYNC;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 4 * sizeof(U32);   //tlv
    cmd->data[0] = PARA_TYPE_TIMESTAMP;
    cmd->data[1] = 2 * sizeof(U32);
    cmd->data[2] = time_sec;
    cmd->data[3] = TLV_PADDING;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_upgrade_x86(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;

    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_FWMGR;	
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdLength = 0;
    cmd->cmdCode = CMD_CODE_FWM_UPGRADE_X86;
    *dcode = cmd->cmdCode;

    device_send_msg(msg);
    return tmp;


}

static I32 device_handle_clean_data(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_DATAM;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_OBSOLETE_PHONE_INFO;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 4 * sizeof(U32);   //tlv
    cmd->data[0] = PARA_TYPE_DATASTOR_OBSOLETE_STEPS;
    cmd->data[1] = 1 * sizeof(U32);
    cmd->data[2] = 1;
    cmd->data[3] = 0;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}


static I32 device_handle_update_storage(I32 time_s, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    msg->hdr.dstID = MODULE_DATAM;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_PHONE_INFO_STORAGE_HOURS;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 4 * sizeof(U32);   //tlv
    cmd->data[0] = PARA_TYPE_DATASTOR_STORAGE_HOURS;
    cmd->data[1] = 2 * sizeof(U32);
    cmd->data[2] = time_s * 24;
    cmd->data[3] = TLV_PADDING;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_get_data(U32 start, U32 end, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_DATAM;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_PHONE_INFO_TRANSFER_START;
    cmd->cmdIndex = cmd_index++;

    //first par: max data per msg.
    cmd->data[0] = PARA_TYPE_DATASTOR_NUM_RECORDS_PER_MESSAGE;
    cmd->data[1] = sizeof(U32);
    cmd->data[2] = DATA_PER_MSG_NUM_MAX;
    cmd->data[3] = 0;
    //2nd par: begin time
    if (start) {

        cmd->data[4] = PARA_TYPE_DATASTOR_BEGIN_TIME;
        cmd->data[5] = 2 * sizeof(U32);
        //here, might be error; used u64_t;
        cmd->data[6] = start;
        cmd->data[7] = 0;
//      *(u64_t)(&cmd[6]) = (u64_t)start;

        if (end) {
            cmd->data[8] = PARA_TYPE_DATASTOR_END_TIME;
            cmd->data[9] = 2 * sizeof(U32);
            cmd->data[10] = end;
            cmd->data[11] = 0;
//          *(u64_t)(&cmd[10]) = (u64_t)end;
            //from begin to end
            cmd->data[12] = PARA_TYPE_DATASTOR_NUM_RECORDS_PER_MESSAGE;
            cmd->data[13] = 1 * sizeof(U32);
            cmd->data[14] = 50;
            cmd->data[15] = 0;
            cmd->cmdLength = 16 * sizeof(U32);
        } else {
            //get data from begin to last
            cmd->cmdLength = 8 * sizeof(U32);
        }
    } else {
        //get full data, 1 tlv. 
        cmd->cmdLength = 4 * sizeof(U32);
    }

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_updata_ack(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_DATAM;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_IND_RPL;
    cmd->cmdCode = CMD_CODE_PHONE_INFO_DATA;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_get_data_stop(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_DATAM;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_PHONE_INFO_TRANSFER_STOP;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

//  *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

I32 device_handle_fep_response(I8 * buf)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_CLI;
    cmd = &msg->cmd;

    cmd->cmdType = CMD_SET_RESPONSE;
    cmd->cmdCode = CMD_CODE_FEP_LOG_LEVEL;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 12;
    cmd->data[0] = 0;
    cmd->data[1] = 4;
	cmd->data[2] = 0; 
//  *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_sleep(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) 
    {
        return -1;
    }

    msg->hdr.dstID = MODULE_SYSTEM;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_SYS_SLEEP;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_system_collect_log(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_SYSTEM;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_SYS_COLLECT_LOG;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;
    cli_app_log(CLI_LOG_NOTICE, "start to collect log\n");
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;


}

static I32 device_handle_wakeup(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_SYSTEM;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_SYS_WAKE;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_factory_reset(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_FWMGR;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_FWM_FACTORY_RESET;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}


static I32 device_handle_update_blackList(I8 *data, I32 action ,I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	I8 *ptr= NULL;
    I32 len = 0, offset = 0;
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_DATAPRO;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_BLACKLIST_CONFIG;
    cmd->cmdIndex = cmd_index++;
    
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    offset =  parapackU32(tlv, PARA_TYPE_DATAPROC_LIST_ACTION, action);
    ptr += offset;
    len += offset;

    tlv = (PARAM *)ptr;
    cli_app_log(CLI_LOG_INFO, "black imsi data is %s \n", data);
    offset = parapackI8(tlv, PARA_TYPE_DATAPROC_IMSI_DATA ,data);
    len += offset;
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_update_whiteList(I8 *data, I32 action ,I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	I8 *ptr= NULL;
    I32 len = 0, offset = 0;
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_DATAPRO;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_WHITELIST_CONFIG;
    cmd->cmdIndex = cmd_index++;
    
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    offset =  parapackU32(tlv, PARA_TYPE_DATAPROC_LIST_ACTION, action);
    ptr += offset;
    len += offset;

    tlv = (PARAM *)ptr;
    cli_app_log(CLI_LOG_INFO, "imsi data is %s \n", data);
    offset = parapackI8(tlv, PARA_TYPE_DATAPROC_IMSI_DATA ,data);
    len += offset;
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}


static I32 device_handle_get_satus(I8 * buf, I32 * dcode)
{

    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_SYSTEM;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_SYS_STATUS;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_get_sys_info(I8 * buf, I32 * dcode)
{

    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_SYSTEM;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_BASIC_INFO;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}



static I32 device_handle_software_update(I8 * data, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    I32 len, off, len1;
	I8 urlData[2048] = {0};
    I8 filename[256] = {0};
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_FWMGR;
	
    cmd = &msg->cmd;
	
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_SYS_UPGRADE;
    cmd->cmdIndex = cmd_index++;
    cmd->data[0] = PARA_TYPE_SYS_UPGRADE_URL;
    len = strlen(data);
    cmd->data[1] = len;
    memcpy((I8 *) (&cmd->data[2]), data, len);
    strcpy(urlData, data);
    
    len = roundup8(len);
    off = len / sizeof(I32) + 2;
    cmd->data[off] = PARA_TYPE_SYS_UPGRADE_MD5SUM;
    cmd->data[off + 1] = 32;
    memcpy((I8 *) (&cmd->data[off + 2]), data + MD5_OFFSET, 32);
    strcpy(filename, shortname(urlData));
    off += roundup8(32)/sizeof(I32) + 2;
    cmd->data[off] = PARA_TYPE_FWM_UPGRADE_FIEL_NAME;
    cmd->data[off + 1] = strlen(filename);
    memcpy((I8 *) (&cmd->data[off + 2]), filename, strlen(filename));
    len1 = roundup8(strlen(filename));    
    cli_app_log(CLI_LOG_CRITICAL, "system upgrade usrl is %s md5 is %s filename is %s \n", data, data + MD5_OFFSET, filename);
    cmd->cmdLength = len + len1 + (2 * sizeof(I32)) + roundup8(32) + (2 * sizeof(I32)) + (2 * sizeof(I32));

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}



static I32 device_handle_gps_request(I32 slotId, I8 *buf, I32 *dcode )
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr; 
    I32 len = 0;
    I8 data[DEV_INFO_NUM_LEN];
    memset(data, 0, DEV_INFO_NUM_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_EUTRAN_GPS_STATE_REQ;
    cli_app_log(CLI_LOG_INFO, "start to get gps infomation form bbu[%d] \n ", slotId);
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(data, "%d", slotId);
    len += parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, data);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp; 
}


static I32 device_handle_sms_snd(I8 * data, I8 * buf, I32 *dcode)
{
	
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    MSSAGE_INFO *minfo = (MSSAGE_INFO *)data;
    I32 len = 0 , offset = 0;
    I32 tmp = (I32) cmd_index;
    I8 *ptr;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }
    msg->hdr.dstID = MODULE_SMS;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_SEND_SMS;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_3G_SMS_CALLED_ID,minfo->phonenum);
    ptr += offset;
    len += offset;

    tlv = (PARAM *)ptr;
    offset = parapackU32(tlv, PARA_TYPE_3G_SMS_FORMAT, PARA_VALUE_3G_SMS_FORMAT_ASCII);
    ptr += offset;
    len += offset;
    
    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_3G_SMS_TEXT, minfo->message);
    len += offset;
    cmd->cmdLength = len;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}


static I32 device_handle_gsm_snf_par_request(I32 type, SNF_INFO * info, I8 * buf,
                                         I32 * dcode)
{
    SNF_PAR *conf;
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;

    I32 tmp = (I32) cmd_index;

    if (msg == NULL || info == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_GSM_CAP;
    cmd = &msg->cmd;

    cmd->cmdCode = CMD_GSM_CFG_AIR_SNIFFER;
    cmd->cmdIndex = cmd_index++;
    conf = (SNF_PAR *) (cmd->data + 2);

    if (type == DEV_OPCODE_SET) {
        conf->autoBccMode = atoi(info->bccMode);
        conf->isAuto = atoi(info->isAuto);
        conf->hour = atoi(info->hour);
        conf->minutes = atoi(info->min);
        conf->second = atoi(info->sec);
        conf->snifferCycle = atoi(info->cycle);
        conf->reverved[0] = 0;
        conf->reverved[1] = 0;

        cmd->data[0] = PARA_TYPE_GSM_SNIFFER_CONFIGURATION;
        cmd->data[1] = sizeof(SNF_PAR);

        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = roundup8(sizeof(SNF_PAR)) + (2 * sizeof(U32));

    } else if (type == DEV_OPCODE_GET) {
        cmd->cmdType = DEV_OPCODE_GET;
        cmd->cmdLength = 4 * sizeof(U32);   //tlv
        cmd->data[0] = PARA_TYPE_GSM_SNIFFER_CONFIGURATION;
        cmd->data[1] = 1 * sizeof(U32);
        cmd->data[2] = 0;
        cmd->data[3] = TLV_PADDING;
    } else {
        return -1;
    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}



static I32 device_handle_gsm_sniferEn_request(I32 type, I32 code, I8 * buf,
                                          I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;

    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_GSM_CAP;	
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    if (type == DEV_OPCODE_SET) {
        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = 0;
        if (code) {
            cmd->cmdCode = CMD_GSM_AIR_SNIFFER_ON;
        } else {
            cmd->cmdCode = CMD_GSM_AIR_SNIFFER_OFF;
        }
    } else if (type == DEV_OPCODE_GET) {
        cmd->cmdType = DEV_OPCODE_GET;
        cmd->cmdCode = CMD_GSM_GET_SNIFFER_STATE;
        cmd->cmdLength = 4 * sizeof(U32);
        cmd->data[0] = PARA_TYPE_PA_STATE;
        cmd->data[1] = 1 * sizeof(U32);
        cmd->data[2] = 0;
        cmd->data[3] = TLV_PADDING;
    } else {
        return -1;
    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}


static I32 device_handle_gsm_update_redet(I32 time_min, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_GSM_CAP;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_GSM_CFG_RECURING_INTERVAL;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 4 * sizeof(U32);   //tlv
    cmd->data[0] = PARA_TYPE_RECURING_INTERVAL;
    cmd->data[1] = 2 * sizeof(U32);
    cmd->data[2] = time_min;
    cmd->data[3] = TLV_PADDING;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}


static I32 device_handle_gsm_request(I32 type, I32 bts, GSM_INFO * info,
                                     I32 intvl, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    GSM_PAR *conf;
    I32 tmp = (I32) cmd_index;

    if (msg == NULL || info == NULL) {
        return -1;
    }
    if (bts != 0 && bts != 1) {
        return -1;
    }
	
    msg->hdr.dstID = MODULE_GSM_CAP;
    cmd = &msg->cmd;

    cmd->cmdCode = CMD_GSM_CFG_WIRELESS;
    cmd->cmdIndex = cmd_index++;
    conf = (GSM_PAR *) (cmd->data + 2);

    if (type == DEV_OPCODE_SET) {
        conf->bcc = atoi(info->bcc);
        conf->mcc = atoi(info->mcc);
        conf->mnc = atoi(info->mnc);
        conf->lac = atoi(info->lac);
        conf->band = atoi(info->band);
        conf->carrier = bts;
        conf->cro = atoi(info->cro);
        conf->rssiMin = atoi(info->rssi);
        conf->thresholdDelta = atoi(info->thld);
        conf->captime = (intvl * 60);
        conf->lowatt = atoi(info->lowatt);
        conf->upatt = atoi(info->upatt);
        conf->cnum = atoi(info->cnum);
        conf->configMode = atoi(info->configMode);
        conf->workMode = atoi(info->workMode);
        conf->startFreq900 = atoi(info->startFreq900);
        conf->endFreq900 = atoi(info->endFreq900);
        conf->startFreq1800 = atoi(info->startFreq1800);
        conf->endFreq1800 = atoi(info->endFreq1800);
        conf->freqOffset = atoi(info->freqOffset);
        cmd->data[0] = PARA_TYPE_GSM_WIRELESS_CONFIGURATION;
        cmd->data[1] = sizeof(GSM_PAR);

        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = roundup8(sizeof(GSM_PAR)) + (2 * sizeof(U32));

    } else if (type == DEV_OPCODE_GET) {
        cmd->cmdType = DEV_OPCODE_GET;
        cmd->cmdLength = 4 * sizeof(U32);   //tlv
        cmd->data[0] = PARA_TYPE_GSM_WIRELESS_CONFIGURATION;
        cmd->data[1] = 1 * sizeof(U32);
        cmd->data[2] = 0;
        cmd->data[3] = TLV_PADDING;
    } else {
        return -1;
    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}



static I32 device_handle_reboot_gsm(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_NOTICE, "reboot gsm bbu\n");
    msg->hdr.dstID = MODULE_GSM_CAP;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_GSM_RESTART;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}


static I32 device_handle_upgrade_gsm(I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_NOTICE, "reboot gsm bbu\n");
    msg->hdr.dstID = MODULE_GSM_CAP;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_GSM_UPGRADE;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_get_gsm_version(I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_NOTICE, "reboot gsm bbu\n");
    msg->hdr.dstID = MODULE_GSM_CAP;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_GSM_GET_VERSION;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}



static I32 device_handle_reboot_cdma(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_NOTICE, "reboot cdma bbu\n");
    msg->hdr.dstID = MODULE_CDMA_CAP;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CDMA_RESTART;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_reboot_wcdma(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_NOTICE, "reboot wcdma bbu\n");
    msg->hdr.dstID = MODULE_WCDMA_CAP;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_WCDMA_RESTART;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_reboot_tdscdma(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_NOTICE, "reboot tdscdma bbu\n");
    msg->hdr.dstID = MODULE_TDSCDMA_CAP;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_TDSCDMA_RESTART;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}


static I32 device_handle_gsm_manual_sniffer(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_DEFAULT, "start do sniffer\n");
    msg->hdr.dstID = MODULE_GSM_CAP;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_GSM_DO_SNIFFER;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_gsm_wirelessEn_request(I32 type, DEV_CONF *devConf, I8 * buf,
                                            I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    I32 rf = 0;
    msg->hdr.dstID = MODULE_GSM_CAP;	
    cmd = &msg->cmd;

    cmd->cmdIndex = cmd_index++;
    if (type == DEV_OPCODE_SET) {
        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdCode = CMD_GSM_RF_CFG ;
        if (atoi(devConf->dev.RFSwitch)  == 1 && atoi(devConf->capGsm.gsm1.enable))
            rf |= (1 << 0);
        if (atoi(devConf->dev.RFSwitch) == 1 && atoi(devConf->capGsm.gsm2.enable))
            rf |= (1 << 1);
         
			
        cmd->cmdLength = 4 * sizeof(U32);   //tlv
        cmd->data[0] = PARA_TYPE_GSM_RF_CONFIG;
        cmd->data[1] = 1 * sizeof(U32);
        cmd->data[2] = rf;
        cmd->data[3] = TLV_PADDING;     
    } 
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}


I32 device_handle_gsm_dnatt(I32 carrier, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_GSM_CAP;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_GSM_TX_ATTUATION;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 8 * sizeof(U32);   //tlv
    cmd->data[0] = PARA_TYPE_TX_ATTUATION;
    cmd->data[1] = 1 * sizeof(U32);
    if (carrier == 0)
        cmd->data[2] = atoi(dev_conf.capGsm.gsm1.lowatt);
    else
        cmd->data[2] = atoi(dev_conf.capGsm.gsm2.lowatt);
    cmd->data[3] = TLV_PADDING;
    cmd->data[4] = PARA_TYPE_GSM_CARRIER_INDEX;
    cmd->data[5] = 1 * sizeof(U32);
    cmd->data[6] = carrier;
    cmd->data[7] = TLV_PADDING;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}


I32 device_handle_gsm_cfg_request(I32 type, DEV_CONF *conf2,I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    GSM_PAR *conf;
    GSM_PAR *conf1;
    GSM_INFO *info = &conf2->capGsm.gsm1;
    GSM_INFO *info1 = &conf2->capGsm.gsm2;
    I32 tmp = (I32) cmd_index;
    
    if (msg == NULL || info == NULL) {
        return -1;
    }
  
	
    msg->hdr.dstID = MODULE_GSM_CAP;
    cmd = &msg->cmd;

    cmd->cmdCode = CMD_GSM_CFG_WIRELESS;
    cmd->cmdIndex = cmd_index++;
    conf = (GSM_PAR *) (cmd->data + 2);
    conf1 = (GSM_PAR *)(conf + 1);
    if (type == DEV_OPCODE_SET) {
        conf->bcc = atoi(info->bcc);
        conf->mcc = atoi(info->mcc);
        if (atoi(info->mnc) == 2)
            conf->mnc = 0;   //0 is mobile
        else 
            conf->mnc = 1;
        conf->lac = atoi(info->lac);
        conf->band = atoi(info->band);
        conf->carrier = PARA_VALUE_GSM_CARRIER_1;
        conf->cro = atoi(info->cro);
        conf->rssiMin = atoi(info->rssi);
        conf->thresholdDelta = atoi(info->thld);
        conf->captime = atoi(info->captime);
        if ((strcmp(dev_conf.dev.protocol, ZHONGDUN) == 0) && atoi(info->PowerLevel) >= 0
             && atoi(info->PowerLevel) < 5)
        {
            
            conf->lowatt = (atoi(info->lowatt) + ((4 - atoi(info->PowerLevel)) * 3));
            cli_app_log(CLI_LOG_NOTICE, "set zhong dun gsm power %d  level %s", conf->lowatt, info->PowerLevel);
        }
        else
        {
            conf->lowatt = atoi(info->lowatt);
        }
        conf->upatt = atoi(info->upatt);
        conf->cnum = atoi(info->cnum);
        conf->configMode = atoi(info->configMode);
        conf->workMode = atoi(info->workMode);
        conf->startFreq900 = atoi(info->startFreq900);
        conf->endFreq900 = atoi(info->endFreq900);
        conf->startFreq1800 = atoi(info->startFreq1800);
        conf->endFreq1800 = atoi(info->endFreq1800);
        conf->freqOffset = atoi(info->freqOffset);
        conf1->bcc = atoi(info1->bcc);
        conf1->mcc = atoi(info1->mcc);
        if (atoi(info->mnc) == 2)
            conf->mnc = 0;   //0 is mobile
        else 
            conf->mnc = 1;
        conf1->lac = atoi(info1->lac);
        conf1->band = atoi(info1->band);
        conf1->carrier = PARA_VALUE_GSM_CARRIER_2;
        conf1->cro = atoi(info1->cro);
        conf1->rssiMin = atoi(info1->rssi);
        conf1->thresholdDelta = atoi(info1->thld);
        conf1->captime = atoi(info1->captime);
        conf1->lowatt = atoi(info1->lowatt);
        conf1->upatt = atoi(info1->upatt);
        conf1->cnum = atoi(info1->cnum);
        conf1->configMode = atoi(info1->configMode);
        conf1->workMode = atoi(info1->workMode);
        conf1->startFreq900 = atoi(info1->startFreq900);
        conf1->endFreq900 = atoi(info1->endFreq900);
        conf1->startFreq1800 = atoi(info1->startFreq1800);
        conf1->endFreq1800 = atoi(info1->endFreq1800);
        conf1->freqOffset = atoi(info1->freqOffset);
        cmd->data[0] = PARA_TYPE_GSM_WIRELESS_CONFIGURATION;
        cmd->data[1] = sizeof(GSM_PAR) * 2;


        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = roundup8(sizeof(GSM_PAR)) * 2 + (2 * sizeof(U32));

    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}
#if 0
static I32 device_handle_cmda_update_redet(I32 time_min, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_CDMA_CAP;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CDMA_CFG_RECURING_INTERVAL;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 4 * sizeof(U32);   //tlv
    cmd->data[0] = PARA_TYPE_CDMA_RECURING_INTERVAL;
    cmd->data[1] = 2 * sizeof(U32);
    cmd->data[2] = time_min;
    cmd->data[3] = TLV_PADDING;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_cdma_snf_par_request(I32 type, SNF_INFO * info, I8 * buf,
                                         I32 * dcode)
{
    SNF_PAR *conf;
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;

    I32 tmp = (I32) cmd_index;

    if (msg == NULL || info == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_CDMA_CAP;
    cmd = &msg->cmd;

    cmd->cmdCode = CMD_CDMA_CFG_AIR_SNIFFER;
    cmd->cmdIndex = cmd_index++;
    conf = (SNF_PAR *) (cmd->data + 2);

    if (type == DEV_OPCODE_SET) {
        conf->autoBccMode = atoi(info->bccMode);
        conf->isAuto = atoi(info->isAuto);
        conf->hour = atoi(info->hour);
        conf->minutes = atoi(info->min);
        conf->second = atoi(info->sec);
        conf->snifferCycle = atoi(info->cycle);
        conf->reverved[0] = 0;
        conf->reverved[1] = 0;

        cmd->data[0] = PARA_TYPE_CDMA_SNIFFER_CONFIGURATION;
        cmd->data[1] = sizeof(SNF_PAR);

        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = roundup8(sizeof(SNF_PAR)) + (2 * sizeof(U32));

    } else if (type == DEV_OPCODE_GET) {
        cmd->cmdType = DEV_OPCODE_GET;
        cmd->cmdLength = 4 * sizeof(U32);   //tlv
        cmd->data[0] = PARA_TYPE_CDMA_SNIFFER_CONFIGURATION;
        cmd->data[1] = 1 * sizeof(U32);
        cmd->data[2] = 0;
        cmd->data[3] = TLV_PADDING;
    } else {
        return -1;
    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_cdma_sniferEn_request(I32 type, I32 code, I8 * buf,
                                          I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;

    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_CDMA_CAP;	
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    if (type == DEV_OPCODE_SET) {
        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = 0;
        if (code) {
            cmd->cmdCode = CMD_CDMA_AIR_SNIFFER_ON;
        } else {
            cmd->cmdCode = CMD_CDMA_AIR_SNIFFER_OFF;
        }
    } else if (type == DEV_OPCODE_GET) {
        cmd->cmdType = DEV_OPCODE_GET;
        cmd->cmdCode = CMD_CDMA_GET_SNIFFER_STATE;
        cmd->cmdLength = 4 * sizeof(U32);
        cmd->data[0] = PARA_TYPE_PA_STATE;
        cmd->data[1] = 1 * sizeof(U32);
        cmd->data[2] = 0;
        cmd->data[3] = TLV_PADDING;
    } else {
        return -1;
    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}


#endif
static I32 device_handle_cdma_request(I32 type, I32 bts, CDMA_INFO * info,
                                     I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    CDMA_PAR *conf;
    I32 tmp = (I32) cmd_index;

    if (msg == NULL || info == NULL) {
        return -1;
    }
    if (bts != 0 && bts != 1) {
        return -1;
    }
	
    msg->hdr.dstID = MODULE_CDMA_CAP;
    cmd = &msg->cmd;

    cmd->cmdCode = CMD_CDMA_CFG_WIRELESS;
    cmd->cmdIndex = cmd_index++;
    conf = (CDMA_PAR *) (cmd->data + 2);

    if (type == DEV_OPCODE_SET) {
        conf->bcc = atoi(info->bcc);
        conf->mcc = atoi(info->mcc);
        conf->mnc = atoi(info->mnc);
        conf->carrier = 0;
        conf->sid = atoi(info->sid);
        conf->nid = atoi(info->nid);
        conf->pn = atoi(info->pn);
        conf->bsid = atoi(info->bsid);
        conf->regnum = atoi(info->regnum);
        conf->captime = atoi(info->captime);
        conf->lowatt = atoi(info->dnatt);
        conf->upatt = atoi(info->upatt);

        conf->workModel = atoi(info->workModel);
        conf->scanTime = atoi(info->scanTime);
        conf->scanPeriod = atoi(info->scanPeriod);
        conf->ResetModel = atoi(info->ResetModel);

        conf->freq1 = atoi(info->freq1);
        conf->workmode1 = atoi(info->workMode1);
        conf->scantime1 = atoi(info->scantime1);
        conf->scancaptime1 = atoi(info->scancaptime1);
        conf->neibor1_freq1 = atoi(info->neibor1Freq1);
        conf->neibor2_freq1 = atoi(info->neibor2Freq1);
        conf->neibor3_freq1 = atoi(info->neibor3Freq1);
        conf->neibor4_freq1 = atoi(info->neibor4Freq1);

        conf->freq2 = atoi(info->freq2);
        conf->workmode2 = atoi(info->workMode2);
        conf->scantime2 = atoi(info->scantime2);
        conf->scancaptime2 = atoi(info->scancaptime2);
        conf->neibor1_freq2 = atoi(info->neibor1Freq2);
        conf->neibor2_freq2 = atoi(info->neibor2Freq2);
        conf->neibor3_freq2 = atoi(info->neibor3Freq2);
        conf->neibor4_freq2 = atoi(info->neibor4Freq2);

        conf->freq3 = atoi(info->freq3);
        conf->workmode3 = atoi(info->workMode3);
        conf->scantime3 = atoi(info->scantime3);
        conf->scancaptime3 = atoi(info->scancaptime3);
        conf->neibor1_freq3 = atoi(info->neibor1Freq3);
        conf->neibor2_freq3 = atoi(info->neibor2Freq3);
        conf->neibor3_freq3 = atoi(info->neibor3Freq3);
        conf->neibor4_freq3 = atoi(info->neibor4Freq3);

        conf->freq4 = atoi(info->freq4);
        conf->workmode4 = atoi(info->workMode4);
        conf->scantime4 = atoi(info->scantime4);
        conf->scancaptime4 = atoi(info->scancaptime4);
        conf->neibor1_freq4 = atoi(info->neibor1Freq4);
        conf->neibor2_freq4 = atoi(info->neibor2Freq4);
        conf->neibor3_freq4 = atoi(info->neibor3Freq4);
        conf->neibor4_freq4 = atoi(info->neibor4Freq4);
        
        cmd->data[0] = PARA_TYPE_CDMA_WIRELESS_CONFIGURATION;
        cmd->data[1] = sizeof(CDMA_PAR);

        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = roundup8(sizeof(CDMA_PAR)) + (2 * sizeof(U32));

    } else if (type == DEV_OPCODE_GET) {
        cmd->cmdType = DEV_OPCODE_GET;
        cmd->cmdLength = 4 * sizeof(U32);   //tlv
        cmd->data[0] = PARA_TYPE_CDMA_WIRELESS_CONFIGURATION;
        cmd->data[1] = 1 * sizeof(U32);
        cmd->data[2] = 0;
        cmd->data[3] = TLV_PADDING;
    } else {
        return -1;
    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_cdma_wirelessEn_request(I32 type, bool rfOn, I8 * buf,
                                            I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_CDMA_CAP;	
    cmd = &msg->cmd;

    cmd->cmdIndex = cmd_index++;
    if (type == DEV_OPCODE_SET) {
        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = 0;
        if (rfOn) {
            cmd->cmdCode = CMD_CDMA_WIRELESS_ON;
			
        } else {
            cmd->cmdCode = CMD_CDMA_WIRELESS_OFF;
        }
    } else if (type == DEV_OPCODE_GET) {
        cmd->cmdType = DEV_OPCODE_GET;
        cmd->cmdCode = CMD_CDMA_GET_WIRELESS_STATE;
        cmd->cmdLength = 4 * sizeof(U32);
        cmd->data[0] = PARA_TYPE_PA_STATE;
        cmd->data[1] = 1 * sizeof(U32);
        cmd->data[2] = 0;
        cmd->data[3] = TLV_PADDING;
    } else {
        return -1;
    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}


static I32 device_handle_wcdma_wirelessEn_request(I32 type, bool rfOn, I8 * buf,
                                            I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_WCDMA_CAP;	
    cmd = &msg->cmd;
    
    cmd->cmdIndex = cmd_index++;
    if (type == DEV_OPCODE_SET) {
        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = 0;
        if (rfOn) {
            cmd->cmdCode = CMD_WCDMA_WIRELESS_ON;
			
        } else {
            cmd->cmdCode = CMD_WCDMA_WIRELESS_OFF;
        }
    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_wcdma_request(I32 type, I32 bts, WCDMA_INFO * info,
                                     I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    WCDMA_PAR *conf;
    I32 tmp = (I32) cmd_index;

    if (msg == NULL || info == NULL) {
        return -1;
    }
    if (bts != 0 && bts != 1) {
        return -1;
    }
	
    msg->hdr.dstID = MODULE_WCDMA_CAP;
    cmd = &msg->cmd;

    cmd->cmdCode = CMD_WCDMA_CFG_WIRELESS;
    cmd->cmdIndex = cmd_index++;
    conf = (WCDMA_PAR *) (cmd->data + 2);

    if (type == DEV_OPCODE_SET) {
        conf->mcc = atoi(info->mcc);
        conf->mnc = atoi(info->mnc);
        conf->lac = atoi(info->lac);
        conf->arfcn = atoi(info->arfcn);
        conf->psc = atoi(info->psc);
        conf->rac = atoi(info->rac);
        conf->cellid = atoi(info->cellId);
        conf->autolac = atoi(info->autoLac);
        conf->dac = atoi(info->dac);
        conf->txPower = atoi(info->txPower);
        conf->rxPower = atoi(info->rxPower);
        
        cmd->data[0] = PARA_TYPE_WCDMA_WIRELESS_CONFIGURATION;
        cmd->data[1] = sizeof(WCDMA_PAR);

        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = roundup8(sizeof(WCDMA_PAR)) + (2 * sizeof(U32));

    } 
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_tdscdma_wirelessEn_request(I32 type, bool rfOn, I8 * buf,
                                            I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_TDSCDMA_CAP;	
    cmd = &msg->cmd;

    cmd->cmdIndex = cmd_index++;
    if (type == DEV_OPCODE_SET) {
        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = 0;
        if (rfOn) {
            cmd->cmdCode = CMD_TDSCDMA_WIRELESS_ON;
			
        } else {
            cmd->cmdCode = CMD_TDSCDMA_WIRELESS_OFF;
        }
    }
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_tdscdma_request(I32 type, I32 bts, TDSCDMA_INFO * info,
                                     I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    WCDMA_PAR *conf;
    I32 tmp = (I32) cmd_index;

    if (msg == NULL || info == NULL) {
        return -1;
    }
    if (bts != 0 && bts != 1) {
        return -1;
    }
	
    msg->hdr.dstID = MODULE_TDSCDMA_CAP;
    cmd = &msg->cmd;

    cmd->cmdCode = CMD_TDSCDMA_CFG_WIRELESS;
    cmd->cmdIndex = cmd_index++;
    conf = (WCDMA_PAR *) (cmd->data + 2);

    if (type == DEV_OPCODE_SET) {
        conf->mcc = atoi(info->mcc);
        conf->mnc = atoi(info->mnc);
        conf->lac = atoi(info->lac);
        conf->arfcn = atoi(info->arfcn);
        conf->psc = atoi(info->psc);
        conf->rac = atoi(info->rac);
        conf->cellid = atoi(info->cellId);
        conf->autolac = atoi(info->autoLac);
        conf->dac = atoi(info->dac);
        conf->txPower = atoi(info->txPower);
        conf->rxPower = atoi(info->rxPower);
        
        cmd->data[0] = PARA_TYPE_TDSCDMA_WIRELESS_CONFIGURATION;
        cmd->data[1] = sizeof(WCDMA_PAR);

        cmd->cmdType = DEV_OPCODE_SET;
        cmd->cmdLength = roundup8(sizeof(WCDMA_PAR)) + (2 * sizeof(U32));

    } 
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_wifi_config_request(I32 type, I32 time_min, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_WIFI;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_WIFI_CFG_WIRELESS;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 4 * sizeof(U32);   //tlv
    cmd->data[0] = PARA_TYPE_WIFI_RECAPT_TIME;
    cmd->data[1] = 2 * sizeof(U32);
    cmd->data[2] = time_min;
    cmd->data[3] = TLV_PADDING;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_wifi_update_redet(I32 time_min, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_WIFI;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_GSM_CFG_RECURING_INTERVAL;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 4 * sizeof(U32);   //tlv
    cmd->data[0] = PARA_TYPE_RECURING_INTERVAL;
    cmd->data[1] = 2 * sizeof(U32);
    cmd->data[2] = time_min;
    cmd->data[3] = TLV_PADDING;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_set_blackList_on(I8 *data, I8* buf, I32* dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;

    I32 len = 0, offset = 0;
    I32 tmp = (I32) cmd_index;

    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	

    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_BLACKLIST_SETTING;

    ptr = (I8 *)(cmd->data);
 
    PARAM *tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_LOC_MODE_IMSI_LIST, data);
    ptr += offset;
    len += offset;
  
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;


}


static I32 device_handle_lte_gain_request(I32 type, I32 *gain, I8 * buf,
                                      I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0, DEV_INFO_NUM_LEN);
    I8 pagain[DEV_INFO_NUM_LEN];
    memset(pagain, 0, DEV_INFO_NUM_LEN);
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_TX_POWER_DB_CONFIG;
    I32 i = 0;
    for ( i = 0; i < 7; i++)
    {
        if (gain[i] != 0)
           break;
    }
    
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(num, "%d", (i + 1));
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    ptr += offset; 
    len += offset;    
    sprintf(pagain, "%d", gain[i]);
    cli_app_log(CLI_LOG_INFO, "set bbu [%d] pagain is %s \n", i, pagain);
    tlv = (PARAM*)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_STD_TX_POWER_DB, pagain);
    ptr += offset;
    len += offset;
    
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    gain[i] = 0;

    return tmp;
}



static I32 device_handle_power_restart(I32 slotId, I8 *buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    if (msg == NULL)
        return IF_APP_ERROR;
    msg->hdr.dstID = MODULE_PM;
    cmd = &msg->cmd;
    I32 len = 0;
    S8 slot = slotId;
    cli_app_log(CLI_LOG_NOTICE, "set pin down so bbu[%d] down \n", slot);
    I32 tmp = (I32) cmd_index;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_PM_RESTART;
    I8 *ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    len =  parapackU8(tlv , PARA_TYPE_PM_GPIO_CTRL_PIN, slot);
    cmd->cmdLength = len ;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;   
}

//send msg to eutran
static I32 device_handle_get_eutran_sync(I32 slotId, I8 * buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr; 
    I32 len = 0;
    I8 data[DEV_INFO_NUM_LEN];
    memset(data, 0, DEV_INFO_NUM_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_EUTRAN_SYNC_STATE_GET;
    cli_app_log(CLI_LOG_INFO, "start to get bbu[%d] sync state\n ", slotId);
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(data, "%d", slotId);
    len += parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, data);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;    
}

static I32 device_handle_setting_eutran_sync_mode(I8 * data, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID =MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_SYNC_MODE_SETTING;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID,data);
    ptr += offset;
    len += offset;
    
    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_SYNC_MODE_CODE, data);
    len += offset;
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;
}

static I32 device_handle_eutran_bbu_upgrade(I32 slotId, I8* operator, I8* buf, I32* dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    I32 fd ;
    I8 num[DEV_INFO_ADD_LEN];
    memset(num, 0, DEV_INFO_ADD_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode =  CMD_CODE_EUTRAN_BBU_UPGRADE;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    
    sprintf(num, "%d", slotId);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    ptr += offset;
    len += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_UPGRADE_IP_ADDR, "192.168.178.111");
    ptr += offset;
    len += offset;
    
    tlv = (PARAM *)ptr;
    if ( strcmp("TDD", operator) == 0 )
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_FILE_NAME, tdd_img);
    else       
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_FILE_NAME, fdd_img);
    ptr += offset;
    len += offset;
    tlv = (PARAM*)ptr;
    if ( strcmp("TDD", operator) == 0 )
    {
        fd = open(tdd_md5, O_RDONLY);
    }
    else
    {
        fd = open(fdd_md5, O_RDONLY);
    }    
    if (fd > 0)
    {   
        memset(num, 0, DEV_INFO_ADD_LEN);
        read(fd, num, 32);
        close(fd);
    }
    else
        return 	IF_APP_ERROR;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_FILE_MD5, num);
    len += offset;
    ptr += offset;

    cli_app_log(CLI_LOG_NOTICE, "BBU[%d] MD5SUM %s \n", slotId, num);

    tlv = (PARAM*)ptr;
    memset(num, 0, DEV_INFO_ADD_LEN);
    sprintf(num, "%d", 1);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_UPGRADE_DOWN_MODE, num);
    len += offset;

     cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;    

}

static I32 device_handle_eutran_bbu_reboot(I32 slotId, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0, DEV_INFO_NUM_LEN);
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_BBU_REBOOT;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(num, "%d", slotId);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    ptr += offset;
    len += offset;
 
    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_REBOOT_DESC_STR, "reboot by fep");
    len += offset;
    
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;      

}

static I32 device_handle_set_ue_filter(I32 enable, I32 *data, I8 *buf, I32 *dcode)
{

    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0, DEV_INFO_NUM_LEN);
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_UEID_FILTER_SWITCH;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(num, "%d", data[0]);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    ptr += offset;
    len += offset;
 
    tlv = (PARAM *)ptr;
    memset(num, 0, DEV_INFO_NUM_LEN);
    sprintf(num, "%d", enable);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_UEID_FILTER_SWITCH, num);
    len += offset;
    ptr += offset;

    if ( enable == 1)
    {
        tlv = (PARAM *)ptr;
        memset(num, 0, DEV_INFO_NUM_LEN);
        sprintf(num, "%d", data[1]);
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_UEID_FILTER_TIMER, num);
        len += offset;
        ptr += offset;
    }
    cli_app_log(CLI_LOG_INFO, "set bbu[%d] fliter intvl time enbale is %d \n", data[0], enable);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;  



}

I32 device_handle_eutran_bbu_state(I8 * buf, I32 soltId, I32 *dcode)
{
	
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 len = 0 ;
    I8 * ptr;
    I8 data[DEV_INFO_NUM_LEN];
    memset(data, 0, DEV_INFO_NUM_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_EUTRAN_BBU_STATE_REQ;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)(ptr);
    sprintf(data, "%d", soltId);
    len = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, data);  

    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}


static I32 device_handle_eutran_software_version(I8 * buf, I32 slotId, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 len = 0 ;
    I8 * ptr;
    I8 data[DEV_INFO_NUM_LEN];
    memset(data, 0, DEV_INFO_NUM_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_EUTRAN_SOFTWARE_VERSION_REQ;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)(ptr);
    sprintf(data, "%d", slotId -48);
    len = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, data);  

    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_eutran_txPower_config(I8 *pagain, I32 slotId,  I32 paState, I8* buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0 ,DEV_INFO_NUM_LEN);
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_TX_POWER_DB_CONFIG;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(num, "%d", slotId);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    ptr += offset; 
    len += offset;    
    
    tlv = (PARAM*)ptr;
	if ((paState == 1))
    {

        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_STD_TX_POWER_DB, pagain);
        cli_app_log(CLI_LOG_INFO, "bbu[%d] pagain is %s\n", slotId, pagain);
    }
    else 
    {
        memset(num, 0, DEV_INFO_NUM_LEN);
        strcpy(num, "127");
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_STD_TX_POWER_DB, num);
		cli_app_log(CLI_LOG_INFO, "bbu[%d] pagain is %s\n", slotId, num);

    }
    ptr += offset;
    len += offset;

   
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;     


}


static I32 device_handle_eutran_pagain_config(I8 *pagain, I32 slotId,  I32 paState, I32 workMode, I32 RFSwitch, bool initcfg, I8* buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0 ,DEV_INFO_NUM_LEN);
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_TX_POWER_DB_CONFIG;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(num, "%d", slotId);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    ptr += offset; 
    len += offset;    
    
    tlv = (PARAM*)ptr;
	cli_app_log(CLI_LOG_INFO, "pastate %d, initconfig %d, workmode %d, rfswitch %d\n", paState, initcfg, workMode, RFSwitch == 1);
	if ((paState == 1) && ( !initcfg ||workMode != 1 ) && (RFSwitch == 1))
    {

        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_STD_TX_POWER_DB, pagain);
        cli_app_log(CLI_LOG_INFO, "bbu[%d] pagain is %s\n", slotId, pagain);
    }
    else 
    {
        memset(num, 0, DEV_INFO_NUM_LEN);
        strcpy(num, "127");
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_STD_TX_POWER_DB, num);
		cli_app_log(CLI_LOG_INFO, "bbu[%d] pagain is %s\n", slotId, num);

    }
    ptr += offset;
    len += offset;

   
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;     


}

static I32 device_handle_eutran_set_bbuIp(I8 * data, I8 *buf, I32* dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_SET_BBU_IP;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, data);
    ptr += offset; 
    len += offset;    

    tlv = (PARAM*)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_IP, data +1);
    ptr += offset;
    len += offset;
    
    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_PORT, data + 2);
     
    len += offset;
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;    
}

static I32 device_handle_eutran_init(LTE_INFO* lteInfo, I8 *workMode, I32 slotId, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0, DEV_INFO_NUM_LEN);
    I8 *ptr;
    I32 offset = 0;
    I32 len = 0 ;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_INIT_CONFIG;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BAND_WIDTH, lteInfo->bandWidth);
    len += offset;
    ptr += offset;
    


    tlv = (PARAM *)ptr;
    sprintf(num, "%d", slotId);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_SNF_SYNC_MODE, lteInfo->syncMode);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_IS_SAVE_FS, lteInfo->isSaveFs);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_SNF_GPS_TM_DELAY, lteInfo->gpsTmDelay);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_WORKING_BAND, lteInfo->band);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_ISMEASUREENABLE, lteInfo->IsMeasureEnable);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_MINRXLEV, lteInfo->minRxLev);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_MINRXLEVOFFSET, lteInfo->minRxLevOffset);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_WORKING_MODE, workMode);
    len += offset;
    ptr += offset;

	if(strcmp(dev_conf.dev.protocol, LOCATION) == 0)
	{
		memset(num, 0, DEV_INFO_NUM_LEN);
		if ((atoi(dev_conf.dev.devtype) == 4097))
		{
			sprintf(num, "%s", "1");    
		}
		else
		{
			sprintf(num, "%s", "2");
		}   
		tlv = (PARAM *)ptr;
		offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_OPERATOR, num);
		len += offset;
		ptr += offset;
	
		tlv = (PARAM *)ptr;
		if ((atoi(dev_conf.dev.devtype) == 4097) && (slotId > 5))
		{
			offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SNF_EARFCN, lteInfo->ctFreqList);
			cli_app_log(CLI_LOG_INFO, "ctfreq is %s \n", lteInfo->ctFreqList);
		}
		else
		{
			offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SNF_EARFCN, lteInfo->freqList); 
			cli_app_log(CLI_LOG_INFO, "freq is %s \n", lteInfo->freqList);
		}   
		len += offset;
		ptr += offset;
		
	}
	else
	{
		tlv = (PARAM *)ptr;
		offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SNF_EARFCN, lteInfo->freqList); 
		cli_app_log(CLI_LOG_INFO, "freq is %s \n", lteInfo->freqList);
		len += offset;
		ptr += offset;

	}

    cli_app_log(CLI_LOG_INFO, "slotd is %d workMode is %s  band %s syncMode is %s IsSaveFs is %s delay is %s Measu is %s \n", slotId, workMode, lteInfo->band, lteInfo->syncMode, lteInfo->isSaveFs, 
	lteInfo->gpsTmDelay, lteInfo->IsMeasureEnable);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;
}

static I32 device_handle_redirect_init(UE_REDIRECT* redirect, I8 *workMode, I8 *buf, I32 *dcode)
{
   
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
   
    I8 *ptr;
    I32 offset = 0;
    I32 len = 0 ;
    I32 tmp = (I32) cmd_index;

#if 0
    cli_app_log(CLI_LOG_NOTICE, "enable %d\n", redirect[0].enable);
    cli_app_log(CLI_LOG_NOTICE, "slotId %d\n", redirect[0].slotId);
    cli_app_log(CLI_LOG_NOTICE, "ranType %d\n", redirect[0].ranType);
    cli_app_log(CLI_LOG_NOTICE, "band %d\n", redirect[0].band);
    cli_app_log(CLI_LOG_NOTICE, "freqList[0] %d\n", redirect[0].freqList[0]);
    cli_app_log(CLI_LOG_NOTICE, "freqList[1] %d\n", redirect[0].freqList[1]);
    cli_app_log(CLI_LOG_NOTICE, "freqList[2] %d\n", redirect[0].freqList[2]);
    cli_app_log(CLI_LOG_NOTICE, "freqList[3] %d\n", redirect[0].freqList[3]);
    cli_app_log(CLI_LOG_NOTICE, "freqList[4] %d\n", redirect[0].freqList[4]);
    cli_app_log(CLI_LOG_NOTICE, "imsiList[0] %d\n", redirect[0].imsiList[0]);
    cli_app_log(CLI_LOG_NOTICE, "imsiList[1] %d\n", redirect[0].imsiList[1]);
    cli_app_log(CLI_LOG_NOTICE, "imsiList[2] %d\n", redirect[0].imsiList[2]);
    cli_app_log(CLI_LOG_NOTICE, "imsiList[3] %d\n", redirect[0].imsiList[3]);
    cli_app_log(CLI_LOG_NOTICE, "imsiList[4] %d\n", redirect[0].imsiList[4]);
#endif

    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_REDIRECT_INIT_CONFIG;
    ptr = (I8 *)(cmd->data);

    
    PARAM *tlv = (PARAM *)ptr;
    offset = parapackV8(tlv, PARA_VALUE_EUTRAN_UE_REDIRECT1, 7, redirect, sizeof(UE_REDIRECT));
    len += offset;
    ptr += offset;

    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);

    
    return tmp;
}

static I32 device_handle_eutran_get_sniffer_status(I8 *data, I8* buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_EUTRAN_GET_SNIFFER_STATUS;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    len = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, data);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;   
}



static I32 device_handle_eutran_stop_sniffer(I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_STOP_SNIFFER;
    cmd->cmdLength = 0;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;   
}

static I32 device_handle_eutran_reset_sniffer(I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_STOP_SNIFFER;
    cmd->cmdLength = 0;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;  

}

static I32 device_handle_eutran_config_rssi(I32 slotId, I8 *data, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0, offset = 0;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0 , DEV_INFO_NUM_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_CONFIG_RSSI;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;

    sprintf(num, "%d", slotId);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    len += parapackI8(tlv, PARA_TYPE_EUTRAN_SNIFFER_RSSI, data);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
   
    device_send_msg(msg);	
    return  tmp; 
}

static I32 device_handle_eutran_get_sniffer_result(I8 * buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_EUTRAN_GET_SNIFFER_RESULT;
    cmd->cmdLength = 0;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp; 
}

static I32 device_handle_eutran_get_rssi(I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_EUTRAN_GET_RSSI;
    cmd->cmdLength = 0;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp; 

}

static I32 device_handle_eutran_config_cell(I32 slotId, DEV_CONF *conf,  I8 * buf, I32 * dcode)
{

    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0 , DEV_INFO_NUM_LEN);
    I8 num1[DEV_INFO_NUM_LEN];
    memset(num1, 0, DEV_INFO_NUM_LEN);
    I32 offset = 0;
    I32 len = 0 ;
    I32 tmp = (I32) cmd_index;
    U16 pciList[6] = {0};
    U16 freqList[6] = {0};
    U16 pci_num = 0;
    U16 freq_num = 0;
    I8 *splt_list;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;      

    cmd->cmdCode = CMD_CODE_EUTRAN_CONFIG_CELL;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    
	if (strcmp(dev_conf.dev.protocol, LOCATION) != 0)
	{
		offset = parapackI8(tlv, PARA_TYPE_EUTRAN_DL_ARFCN, conf->capLte.lte[slotId - 1].dl_earfcn);
		len += offset;
		ptr += offset;    

		tlv = (PARAM *)ptr;
		offset = parapackI8(tlv, PARA_TYPE_EUTRAN_UL_ARFCN, conf->capLte.lte[slotId - 1].ul_earfcn);
		len += offset;
		ptr += offset;
	}
	else
	{
		I8 freqList[DEV_INFO_PAR_LEN] = {0};
		I8 ulEarfcn[DEV_INFO_NUM_LEN] = {0};
		I8 dlEarfcn[DEV_INFO_NUM_LEN] = {0};
		U16 ulearfcn = 0;
		U16 dlearfcn = 0;
		if (slotId > 5)
		{
			if (atoi(dev_conf.dev.devtype) == 4097)
			{
				strcpy(freqList, conf->capLte.lte[slotId - 1].ctFreqList);
			}
			else
			{
				strcpy(freqList, conf->capLte.lte[slotId - 1].freqList);
			}
			splt_list = strtok(freqList, ",");
			if (splt_list != NULL)
			{
				dlearfcn = atoi(splt_list);
				ulearfcn = (dlearfcn + 18000);
			}
		}
		else
		{
			strcpy(freqList, conf->capLte.lte[slotId - 1].freqList);
			splt_list = strtok(freqList, ",");
			if (splt_list != NULL)
			{
				dlearfcn = ulearfcn = atoi(splt_list);
			}
		}
		sprintf(ulEarfcn, "%d", ulearfcn);
		sprintf(dlEarfcn, "%d", dlearfcn);
		
		offset = parapackI8(tlv, PARA_TYPE_EUTRAN_DL_ARFCN, dlEarfcn);
		len += offset;
		ptr += offset;    

		tlv = (PARAM *)ptr;
		offset = parapackI8(tlv, PARA_TYPE_EUTRAN_UL_ARFCN, ulEarfcn);
		len += offset;
		ptr += offset;
		

	}
    tlv = (PARAM *)ptr;
    sprintf(num, "%d", slotId);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    memset(num, 0 , DEV_INFO_NUM_LEN);
    len += offset;
    ptr += offset;


    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_PCI, conf->capLte.lte[slotId - 1].pci);
    len += offset;
    ptr += offset;
    
	if (slotId > 5 && strcmp(dev_conf.dev.protocol, LOCATION) == 0)
	{
		tlv = (PARAM *)ptr;
		if ((atoi(dev_conf.dev.devtype) == 4097))
		{
			offset = parapackI8(tlv, PARA_TYPE_EUTRAN_PLMN_ID, "46011");
		}
		else
		{
			offset = parapackI8(tlv, PARA_TYPE_EUTRAN_PLMN_ID, "46001");
		}
		len += offset;
		ptr += offset;
	}
	else
	{
		tlv = (PARAM *)ptr;
		offset = parapackI8(tlv, PARA_TYPE_EUTRAN_PLMN_ID, conf->capLte.lte[slotId - 1].plmnid);
		len += offset;
		ptr += offset;

	}


    tlv = (PARAM *)ptr;	
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_SNIFFER_TYPE, conf->capLte.lte[slotId -1].configMode);
    len += offset;
    ptr += offset;


    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_TAC, conf->capLte.lte[slotId - 1].tac);
    len += offset;
    ptr += offset;
   
    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_IS_MEASURE_ENABLE, conf->capLte.lte[slotId - 1].IsMeasureEnable);
    len += offset;
    ptr += offset;
    
    I8 neiCell[DEV_INFO_PAR_LEN] = {0};
    I8 neiFreq[DEV_INFO_PAR_LEN] = {0};
    strcpy(neiCell, conf->capLte.lte[slotId - 1].neiborcell);
    strcpy(neiFreq, conf->capLte.lte[slotId - 1].abnorfreq);
    splt_list = strtok(neiCell, ",");
    if (splt_list != NULL)
    {
        if (atoi(splt_list) != 0)
        {
            pciList[pci_num++] = atoi(splt_list);
        }
    }
    while((splt_list = strtok(NULL, ",")) != NULL)
    {
        pciList[pci_num++] = atoi(splt_list);
        if (pci_num > 5)
            break;
    }    

    splt_list = strtok(neiFreq, ",");
    if (splt_list != NULL)
    {
        if (atoi(splt_list) != 0)
        {
            freqList[freq_num++] = atoi(splt_list);
        }
    }
    while((splt_list = strtok(NULL, ",")) != NULL)
    {
        freqList[freq_num++] = atoi(splt_list);
        if (freq_num > 5)
            break;
    }
    if (pci_num > 0)
    {
        tlv = (PARAM *)ptr;
        offset = parapackU16(tlv, PARA_TYPE_EUTRAN_SNIFFER_PCI_LIST, pci_num, pciList);
        len += offset;
        ptr += offset;
    }

    if (freq_num > 0)
    {
        tlv = (PARAM *)ptr;
        offset = parapackU16(tlv, PARA_TYPE_EUTRAN_ARFCN_LIST, freq_num, freqList);
        len += offset;
        ptr += offset;
    }       
    cmd->cmdLength = len;

	
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;


}


static I32 device_handle_eutran_update_cell(I32 slotId, DEV_CONF *conf, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0 , DEV_INFO_NUM_LEN);
    I8 num1[DEV_INFO_NUM_LEN];
    memset(num1, 0 , DEV_INFO_NUM_LEN);
    I32 offset = 0;
    I32 len = 0 ;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET; 

    cmd->cmdCode = CMD_CODE_EUTRAN_UPDATE_CELL;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(num, "%d", slotId);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    memset(num, 0 , DEV_INFO_NUM_LEN);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_DL_ARFCN, conf->capLte.lte[slotId - 1].dl_earfcn); 
    len += offset;
    ptr += offset;

    
	if (slotId > 5 && strcmp(dev_conf.dev.protocol, LOCATION) == 0)
	{
		tlv = (PARAM *)ptr;
		if ((atoi(dev_conf.dev.devtype) == 4097))
		{
			offset = parapackI8(tlv, PARA_TYPE_EUTRAN_PLMN_ID, "46011");
		}
		else
		{
			offset = parapackI8(tlv, PARA_TYPE_EUTRAN_PLMN_ID, "46001");
		}
		len += offset;
		ptr += offset;
	}
	else
	{
		tlv = (PARAM *)ptr;
		offset = parapackI8(tlv, PARA_TYPE_EUTRAN_PLMN_ID, conf->capLte.lte[slotId - 1].plmnid);
		len += offset;
		ptr += offset;

	}

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_TAC, conf->capLte.lte[slotId - 1].tac);
    len += offset;
    ptr += offset;
        
    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_IS_MEASURE_ENABLE, conf->capLte.lte[slotId - 1].IsMeasureEnable);
    len += offset;
    ptr += offset;

    cmd->cmdLength = len;
	
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}


static I32 device_handle_eutran_sniffer_request(I32 Auto,  I8 * buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0, DEV_INFO_NUM_LEN);
    U32 freq[12];
    U16 freq1[12];
    I32 freq_num = 0;
    memcpy(&freq, cmdList.commandList[cmdList.cmdIndex - 1].data, sizeof(U32) * 12);
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_START_SNIFFER;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(num, "%d", 1);  //make sure device can work normally ,after mamual sniffer
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_AUTO_CONFIG_CELL, num);
    ptr += offset;
    len += offset;

    tlv = (PARAM *)ptr;
    memset(num, 0, DEV_INFO_NUM_LEN);
    sprintf(num, "%d", cmdList.commandList[cmdList.cmdIndex - 1].cellId);

    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    ptr += offset;
    len += offset;
 //   freq_num++;
    for (; freq_num < 12; freq_num++)
    {
        if (freq[freq_num] == 0)
            break;
        else
        {
            freq1[freq_num - 1] = freq[freq_num];
        }
    }

    tlv = (PARAM *)ptr;
    offset = parapackU16(tlv, PARA_TYPE_EUTRAN_SNIFFER_EARFCN_RANGE, freq_num - 1 , freq1);
    len += offset;
    ptr += offset;  

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_SNIFFER_RSSI, "60");
    len += offset;
    ptr += offset; 
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp; 
}

static I32 device_handle_eutran_auto_sniffer_request(DEV_CONF *conf, I32 *autoslot, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0, offset = 0, autosnf = 0;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0, DEV_INFO_NUM_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_CFG_AUTO_SNF;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    I32 i = 0;
    for (; i < 7; i ++)
    {
        if (autoslot[i] != 0)
            break;
    }
    autoslot[i] = 0;
    sprintf(num, "%d", (i + 1));
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    ptr += offset;
    len += offset; 
    if (atoi(conf->snfLte.enable) == 1)
    {
        autosnf = PARA_VALUE_EUTRAN_AUTO_SNF_SET;
        tlv = (PARAM *)ptr;
        memset(num, 0, DEV_INFO_NUM_LEN);
        sprintf(num, "%02d:%02d", atoi(conf->snfLte.snf_tm[i].hour), atoi(conf->snfLte.snf_tm[i].min));
        cli_app_log(CLI_LOG_INFO, "bbu is [%d] auto sniffer time %s \n", (i+1), num);
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_AUTO_SNF_TIME, num);
        ptr += offset;
        len += offset;
  
        tlv = (PARAM *)ptr;
        memset(num, 0, DEV_INFO_NUM_LEN);
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_SNIFFER_RSSI, "60");
        ptr += offset;
        len += offset;

        tlv = (PARAM *)ptr;
 //       memset(num, 0, DEV_INFO_NUM_LEN);
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_AUTO_SNF_DAY, conf->snfLte.cycle);
        ptr += offset;
        len += offset;

        tlv = (PARAM *)ptr;
        U16 range[2] = {0};
        range[0] = atoi(conf->capLte.lte[i].dl_earfcn);
        range[1] = atoi(conf->capLte.lte[i].ul_earfcn);
        
        offset = parapackU16(tlv, PARA_TYPE_EUTRAN_SNIFFER_EARFCN_RANGE, 2, range);
        ptr += offset;
        len += offset;
  
        tlv = (PARAM *)ptr;
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_UL_ARFCN, conf->capLte.lte[i].ul_earfcn);
        ptr += offset;
        len += offset;
        
    }
    else
        autosnf = PARA_VALUE_EUTRAN_AUTO_SNF_DEL;
    tlv = (PARAM *)ptr;
    offset = parapackU32(tlv, PARA_TYPE_EUTRAN_AUTO_SNF_OPER_CODE, autosnf);
    len += offset;
    cmd->cmdLength = len;  
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp; 
}




static I32 device_handle_eutran_show_bbu_info(I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_GET;
    cmd->cmdCode = CMD_CODE_EUTRAN_SHOW_BBU_INFO;
    cmd->cmdLength = 0;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;

}


static I32 device_handle_pm_reboot_device(I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_PM;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_PM_REBOOT_DEVICE;
    cmd->cmdLength = 0;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;

}

static I32 device_handle_ue_redirect(I32 Opercode, I8 *data, I8 * buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0, offset = 0, i = 0;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0, DEV_INFO_NUM_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    UE_REDIRECT *ue = (UE_REDIRECT *)data;
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_REDIT_CONFIG;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    *(I32 *)tlv->paraValue = Opercode;
    tlv->paraType = PARA_TYPE_EUTRAN_UE_REDIRECT_OPER_CODE;
    tlv->paraLength = sizeof(I32);
    offset = roundup8(sizeof(PARAM) + tlv->paraLength);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    memset(num, 0 ,DEV_INFO_NUM_LEN);
    sprintf(num, "%d", ue->slotId);
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    len += offset;
    ptr += offset;
    if (Opercode == 1)
    {    
        tlv = (PARAM *)ptr;
        memset(num, 0 ,DEV_INFO_NUM_LEN);
        sprintf(num, "%d", ue->ranType);
        offset = parapackI8(tlv, PARA_TYPE_RAN_TYPE, num);
        len += offset;
        ptr += offset;
         
    
        tlv = (PARAM *)ptr;
        memset(num, 0 ,DEV_INFO_NUM_LEN);
        sprintf(num, "%d", ue->band);
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_SNIFFER_BAND, num);
        len += offset;
        ptr += offset;

        tlv = (PARAM *)ptr;
        I8 list[DEV_INFO_PAR_LEN];
        I32 list_len = 0;
        memset(list, 0, DEV_INFO_PAR_LEN);
        list_len = sprintf(list, "%d", ue->freqList[i++]);
        while((ue->freqList[i] > 0) && (i < 6))
        {
            list[list_len] = ',';
            list_len++;
            list_len += sprintf(list + list_len, "%d", ue->freqList[i]);
            i++;

        }
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_ARFCN_LIST, list);
        len += offset;
        ptr += offset;

        tlv = (PARAM *)ptr;
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_LOC_MODE_IMSI_LIST, data + sizeof(UE_REDIRECT));
        len += offset;
        ptr += offset; 
    }   

    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;

}

static I32 device_handle_lte_update_wifi_request(DEV_CONF *conf, I32 *slot, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0, DEV_INFO_NUM_LEN);
    I8 pagain[DEV_INFO_NUM_LEN];
    memset(pagain, 0, DEV_INFO_NUM_LEN);
    I8 *ptr;
    I32 len = 0;
    I32 offset = 0;
    
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_TX_POWER_DB_CONFIG;
    I32 i = 0;

    for (i = 0; i < 7 ; i++)
    {
        if (slot[i] != 0)
           break;

    }
    slot[i] = 0;
    if (atoi(dev_conf.capLte.enable) == 1) 
    {
        if (atoi(conf->pa[i].gain) < 17)
            strcpy(conf->pa[i].gain, "17");
        strcpy(pagain, conf->pa[i].gain);	
    }
    else 
    {
        strcpy(pagain, "127");
    }
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(num, "%d", (i+1));
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_SLOT_ID, num);
    ptr += offset; 
    len += offset;    

    tlv = (PARAM*)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_STD_TX_POWER_DB, pagain);
    ptr += offset;
    len += offset;
    
    cli_app_log(CLI_LOG_INFO, "set bbu[%s] wireless power %s \n", num, pagain);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;




}

static I32 device_init_vaild_pa(DEV_CONF *conf, I32 devType, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    I8 *ptr;
	I32 offset = 0;
    I32 len = 0;
    I32 paState[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    if (msg == NULL) {
        return IF_APP_ERROR;
    }
    I32 i = 0;
    if ( atoi(conf->capGsm.isSupported) == 1)
    {
        paState[7] = 1;
    }
   
    if ( atoi(conf->capLte.isSupported) == 1 )
    {
        for ( ; i < 7; i++)
        {
            if (atoi(conf->capLte.lte[i].enable) == 1)
            {
                if (strcmp(dev_conf.dev.protocol, LOCATION) != 0)
                {
                    if (atoi(conf->capLte.lte[i].band) == 38)
                    {
                        paState[0] = 1;
                    }
                    else if (atoi(conf->capLte.lte[i].band) == 39)
                    {
                        paState[1] = 1;
                    }
                    else if (atoi(conf->capLte.lte[i].band) == 40)
                    {
                        paState[2] = 1;
                    }
                    else if (atoi(conf->capLte.lte[i].band) == 1)
                    {
                        paState[5] = 1;
                    }
                    else if (atoi(conf->capLte.lte[i].band) == 3)
                    {
                        paState[6] = 1;
                    }
                }
                else
                {
                    paState[i] = 1;
                }
            }

        }
    } 
    
    if ( atoi(conf->capCdma.isSupported) == 1 )
    {
        paState[8] = 1;
    } 
    
    if ( atoi(conf->capWcdma.isSupported) == 1 )
    {
        paState[5] = 1;
    }

    if ( atoi(conf->capTdscdma.isSupported) == 1 )
    {
        paState[10] = 1;
    }
	paState[11] = atoi(dev_conf.dev.tempThreshold);
	cli_app_log(CLI_LOG_NOTICE, "len %d temp is %d \n", len, paState[11]);
    msg->hdr.dstID = MODULE_PA;
    cmd = &msg->cmd;
    cmd->cmdCode = CMD_CODE_SET_VAILD_PA ;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    tlv->paraType = PARA_TYPE_VALID_PA;
    tlv->paraLength = sizeof(I32) * 12;
    memcpy(tlv->paraValue, paState, sizeof(I32)*12);
    len = roundup8(sizeof(I32) * 14);


	
	cmd->cmdLength = len;
    *dcode = cmd->cmdCode ;
    device_send_msg(msg);
    return tmp;    



}

static I32 device_handle_eutran_set_work_period(I32 type, I8* buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 len = 0;
    I8 num[DEV_INFO_NUM_LEN] = {0};
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_WORK_PERIOD_SETTING;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    sprintf(num, "%d", type);
    cli_app_log(CLI_LOG_INFO, "set workPeriod is %d \n", type);
    len = parapackI8(tlv, PARA_TYPE_EUTRAN_IS_POWER_OFF, num);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;   
}

//handle multiple command from service
I32 return_request_conf(I32 dcode, I32 ret_req)
{
    cli_app_log(CLI_LOG_INFO, "dcode ========= %04x \n", dcode);
    int ret = IF_APP_OK;
    switch(dcode)
    {
        case CMD_CODE_EUTRAN_START_SNIFFER:
            ret = REQUEST_EUTRAN_MANUAL_SNIFFER;
            break;

        case CMD_CODE_EUTRAN_TX_POWER_DB_CONFIG:
            if ((ret_req == IF_APP_LTE_WIFI_SWITCH))
                ret = REQUEST_UPDATA_WIFI;
            else if ((ret_req == IF_APP_PA_GAIN ))
                ret = REQUEST_UPDATA_PA_GAIN;
            else
                ret = REQUEST_UPDATA_TX_POWER;
            break;

        case CMD_CODE_EUTRAN_CFG_AUTO_SNF:
            ret =  REQUEST_EUTRAN_AUTO_SNIFFER_PAR;
            break;

        case CMD_CODE_EUTRAN_BBU_UPGRADE:
            ret = REQUEST_EUTRAN_BBU_UPGRADE;
            break;

        case CMD_CODE_FWM_UPGRADE_X86:
            ret = REQUEST_UPGRADE_X86;
            break;

        default:
            break;
    }

    return ret ;
}

static I32 device_handle_sr_blackList(bool start ,I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_DATAPRO;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    if (start)
    {
        cmd->cmdCode = CMD_CODE_BLACKLIST_IMSI_TRANSFER_START;
        *dcode = cmd->cmdCode;
    }
    else
        cmd->cmdCode = CMD_CODE_BLACKLIST_IMSI_TRANSFER_STOP;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;
    device_send_msg(msg);
    return tmp;
    
}


static I32 device_handle_sr_blackList_inack(I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_DATAPRO;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_IND_RPL;
    cmd->cmdCode = CMD_CODE_BLACKLIST_IMSI_DATA;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;
    device_send_msg(msg);
    return tmp;
    
}



static I32 device_handle_sms_msg(I32 enable, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_SMS;
    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    if (enable == 1)
        cmd->cmdCode = CMD_CODE_SMS_MAINT_ON;
    else
        cmd->cmdCode = CMD_CODE_SMS_MAINT_OFF;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;
    *dcode = cmd->cmdCode;

    device_send_msg(msg);
    return tmp;
}

static I32  device_handle_sms_key(I8 *key, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    I32 len = 0;
	I8 *ptr;
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_SMS;
    cmd = &msg->cmd;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_SMS_KEY;
    cmd->cmdIndex = cmd_index++;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    len = parapackI8(tlv, PARA_TYPE_3G_SMS_KEY, key);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;

    device_send_msg(msg);
    return tmp;
}

static I32  device_handle_set_pa_power(bool enable, I32 id, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
    I32 len = 0;
	I8 *ptr;
    if (msg == NULL) {
        return -1;
    }

    msg->hdr.dstID = MODULE_PA;
    cmd = &msg->cmd;
    cmd->cmdType = DEV_OPCODE_SET;
    if (enable)
        cmd->cmdCode = CMD_CODE_PA_SWITCH_ON;
    else
        cmd->cmdCode = CMD_CODE_PA_SWITCH_OFF;
    cmd->cmdIndex = cmd_index++;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    tlv->paraType = PARA_TYPE_PA_ADDR;
    memcpy(tlv->paraValue, (U8 *)&id, 1);
    tlv->paraLength = 1;
    cmd->cmdLength = roundup8(sizeof(PARAM) + 1);
    *dcode = cmd->cmdCode;

    device_send_msg(msg);
    return tmp;
}


static I32 device_handle_lte_and_wcdma_manual_sniffer(I32 code, I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_DEFAULT, "start do sniffer\n");
    msg->hdr.dstID = MODULE_SCANNER;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = code;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;

}

static I32 device_handle_remote_ssh_off(I8 * buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 tmp = (I32) cmd_index;
	
    if (msg == NULL) {
        return -1;
    }
    cli_app_log(CLI_LOG_NOTICE, "stop remote ssh \n");
    msg->hdr.dstID = MODULE_SYSTEM;

    cmd = &msg->cmd;

    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_SYS_SSH_OFF;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdLength = 0;

    *dcode = cmd->cmdCode;
    device_send_msg(msg);
	ssh_state = '0';
    return tmp;

}

static I32 device_handle_remote_ssh_on(REMOTE_SSH *remoteSsh, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I32 offset = 0;
    I32 len = 0 ;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_SYSTEM;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET; 

    cmd->cmdCode = CMD_CODE_SYS_SSH_ON;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_SYS_REMOTE_SSH_PORT, remoteSsh->port);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_SYS_REMOTE_SSH_USER, remoteSsh->user); 
    len += offset;
    ptr += offset;

    
    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_SYS_REMOTE_SSH_PASSWORD, remoteSsh->password);
    len += offset;
    ptr += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_SYS_REMOTE_SSH_SERVERIP, remoteSsh->serverAddr);
    len += offset;
    ptr += offset;
    
    cli_app_log(CLI_LOG_NOTICE, "start remote ssh %s %s %s %s \n", remoteSsh->port, remoteSsh->user, remoteSsh->password, remoteSsh->serverAddr);
    cmd->cmdLength = len;
	
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
	ssh_state = '1';
    return tmp;


}

static I32 device_handle_set_bbu_scan(I32 time, I8 *buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 len = 0 ;
    I8 * ptr;
  //  I8 data[DEV_INFO_NUM_LEN];
   // memset(data, 0, DEV_INFO_NUM_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_SET_SCAN_MODE;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)(ptr);
   // sprintf(data, "%d", time);
    len = parapackU32(tlv, PARA_TYPE_EUTRAN_SCAN_PERIOD, time);  
    cli_app_log(CLI_LOG_INFO, "set eutran bbu scan time is %d \n", time);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}

static I32 device_handle_set_location_enable(I8 *buf, I32 * dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I32 len = 0 ;
    I8 * ptr;
  //  I8 data[DEV_INFO_NUM_LEN];
   // memset(data, 0, DEV_INFO_NUM_LEN);
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_LOCATION_ENABLE_SETTING;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)(ptr);
    int enable = 0;
    if (strcmp(dev_conf.dev.protocol, LOCATION) == 0)
    {
        enable = 1;
    }
    
    len = parapackU32(tlv, PARA_TYPE_EUTRAN_LOCATION_MODE_ENABLE, enable);  
    cli_app_log(CLI_LOG_INFO, "set eutran location enable  is %d \n", enable);
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;
}


static I32 device_handle_set_location_on(I32 type, I8 *imsiList, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I8 DuplexMode[DEV_INFO_NUM_LEN];
    memset(DuplexMode , 0, DEV_INFO_NUM_LEN);
    I32 len = 0, offset = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_LOCATION_MODE_SETTING;

    ptr = (I8 *)(cmd->data);
 
    PARAM *tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_LOC_MODE_ENABLE, "on");
    ptr += offset;
    len += offset;

    if (type == 1)
    {
        strcpy(DuplexMode, "TDD");
    }
    else
        strcpy(DuplexMode, "FDD");
    cli_app_log(CLI_LOG_INFO, "set location  on type is %s imsiList %s\n", DuplexMode, imsiList);

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_DUPLEX_MODE, DuplexMode);
    ptr += offset;
    len += offset;

    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_LOC_MODE_IMSI_LIST, imsiList);
    ptr += offset;
    len += offset;

	U16 power[7] = {0, 0, 0, 0, 0, 0, 0};
	int i = 0;
	for (i = 0; i < 7 ; i++)
	{
		power[i] = atoi(dev_conf.pa[i].gain);
	}

	tlv = (PARAM *)ptr;
    offset = parapackU16(tlv, PARA_TYPE_EUTRAN_POWER_LIST, 7 , power);
    len += offset;
    ptr += offset;  

    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;
}

static I32 device_handle_set_location_off(I32 type, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *)buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I8 DuplexMode[DEV_INFO_NUM_LEN];
    memset(DuplexMode , 0, DEV_INFO_NUM_LEN);
    I32 len = 0, offset = 0;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET;
    cmd->cmdCode = CMD_CODE_EUTRAN_LOCATION_MODE_SETTING;

    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_LOC_MODE_ENABLE, "off");
    ptr += offset;
    len += offset;

    if (type == 1)
    {
        strcpy(DuplexMode, "TDD");
    }
    else
        strcpy(DuplexMode, "FDD");
    cli_app_log(CLI_LOG_INFO, "set location  off type is %s \n", DuplexMode);
    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_DUPLEX_MODE, DuplexMode);
    ptr += offset;
    len += offset;
    cmd->cmdLength = len;
    *dcode = cmd->cmdCode;
    device_send_msg(msg);	
    return  tmp;
}

static I32 device_handle_chang_teleOperator(I32 type, WIRELESS_LTE_INFO info, I8 *buf, I32 *dcode)
{
    DEV_MSG *msg = (DEV_MSG *) buf;
    DEV_CMD *cmd;
    I8 *ptr;
    I8 num[DEV_INFO_NUM_LEN];
    memset(num, 0 , DEV_INFO_NUM_LEN);
    
    I32 offset = 0,  slotId = 0;
    I32 len = 0 ;
    I32 tmp = (I32) cmd_index;
    if(msg == NULL)
    {
        return IF_APP_ERROR;
    }	
    msg->hdr.dstID = MODULE_EUTRAN_SNIFFER;
    cmd = &msg->cmd;
    cmd->cmdIndex = cmd_index++;
    cmd->cmdType = DEV_OPCODE_SET; 

    cmd->cmdCode = CMD_CODE_EUTRAN_CHANG_TELEOPERATOR;
    ptr = (I8 *)(cmd->data);
    PARAM *tlv = (PARAM *)ptr;
    
	if (type == 4097)
	{
    	sprintf(num, "%d", 1);
	}
	else 
	{
		sprintf(num, "%d", 2);
	}
	       
    tlv = (PARAM *)ptr;
    offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU_OPERATOR, num);
    len += offset;
    ptr += offset;


    tlv = (PARAM *)ptr;
    if ((type == 4097))
    {
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU6_DL_ARFCN, info.lte[5].ctFreqList);
        cli_app_log(CLI_LOG_INFO, "ctfreq is %s \n", info.lte[5].ctFreqList);
    }
    else
    {
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU6_DL_ARFCN, info.lte[5].freqList); 
        cli_app_log(CLI_LOG_INFO, "freq is %s \n", info.lte[5].freqList);
    }

    ptr += offset;
    len += offset;


    tlv = (PARAM *)ptr;
    if ((type == 4097))
    {
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU7_DL_ARFCN, info.lte[6].ctFreqList);
        cli_app_log(CLI_LOG_INFO, "ctfreq is %s \n", info.lte[6].ctFreqList);
    }
    else
    {
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_BBU7_DL_ARFCN, info.lte[6].freqList); 
        cli_app_log(CLI_LOG_INFO, "freq is %s \n", info.lte[6].freqList);
    }


    ptr += offset;
    len += offset;

    
    tlv = (PARAM *)ptr;
     if ((type == 4097))
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_PLMN_ID, "46011");
    else
        offset = parapackI8(tlv, PARA_TYPE_EUTRAN_PLMN_ID, "46001");
    len += offset;
    ptr += offset;

       
    cmd->cmdLength = len;
	
    *dcode = cmd->cmdCode;
    device_send_msg(msg);
    return tmp;    

}

I32 device_handle_request(I32 type, DEV_CONF * conf,  I8 * buf, I32 * data,
                          I32 * dcode)
{
    I32 ret = -1;
    U32 *par = (U32 *) data;
	if (cmd_index > EVENT_QUEUE_SIZE )
	{
		cmd_index = 0;

	}
    if (conf == NULL || buf == NULL) {
        return ret;
    }
    switch (type) {



        case REQUEST_UPDATA_GSM1:
            ret = device_handle_gsm_request(DEV_OPCODE_SET, 0, &conf->capGsm.gsm1, atoi(conf->capGsm.intvl), buf, dcode);
            break; 

        case REQUEST_UPDATA_GSM2:
            ret = device_handle_gsm_request(DEV_OPCODE_SET, 1, &conf->capGsm.gsm2, atoi(conf->capGsm.intvl), buf, dcode);
            break;

        case REQUEST_UPDATA_GSM_ENABLE:
            ret = device_handle_gsm_wirelessEn_request(DEV_OPCODE_SET, conf, buf, dcode);
            break;
            
        case REQUEST_UPDATA_GSM_SNIFER:
            ret = device_handle_gsm_sniferEn_request(DEV_OPCODE_SET, atoi(conf->snfGsm.enable), buf, dcode);
            break;

        case REQUEST_UPDATA_GSM_SNIFER_PAR:
            ret = device_handle_gsm_snf_par_request(DEV_OPCODE_SET, &conf->snfGsm, buf, dcode);
            break;

        case REQUEST_UPDATA_GSM_REDET:
            ret = device_handle_gsm_update_redet(atoi(conf->capGsm.intvl), buf, dcode);
         	break;

        case REQUEST_GSM_MANUAL_SNIFFER:
            ret = device_handle_gsm_manual_sniffer(buf, dcode);
            break;

        case REQUEST_UPDATA_GSM_PA:
            ret = device_handle_gsm_dnatt(cmdList.commandList[cmdList.cmdIndex -1].cellId - 8,  buf, dcode);
            break;

        case REQUEST_GSM_REBOOT:
            ret = device_handle_reboot_gsm(buf, dcode);
            break;

        case REQUEST_GSM_UPGRADE:
            ret = device_handle_upgrade_gsm(buf, dcode);
            break;

        case REQUEST_GSM_GET_VERSION:
            ret = device_handle_get_gsm_version(buf, dcode);
            break;

        case REQUEST_UPDATA_GSM_CFG:
            ret = device_handle_gsm_cfg_request(DEV_OPCODE_SET, conf, buf, dcode);
            break;

        case REQUEST_UPDATA_CDMA: 
            ret = device_handle_cdma_request(DEV_OPCODE_SET, 0, &conf->capCdma.cdma, buf, dcode);
            break;

        case REQUEST_UPDATA_CDMA_WIFI:
            ret = device_handle_cdma_wirelessEn_request(DEV_OPCODE_SET, (atoi(conf->capCdma.enable) == 1) && (atoi(conf->dev.RFSwitch) == 1), buf, dcode);
            break;

        case REQUEST_CDMA_REBOOT:
            ret = device_handle_reboot_cdma(buf, dcode);
            break;
            
        case REQUEST_UPDATA_WCDMA:
            ret = device_handle_wcdma_request(DEV_OPCODE_SET, 0, &conf->capWcdma.wcdma, buf, dcode);
            break;
             
        case REQUEST_UPDATA_WCDMA_ENABLE:
            cli_app_log(CLI_LOG_NOTICE, "wcdma enable %d  rf switch %d \n", atoi(conf->capWcdma.enable), atoi(conf->dev.RFSwitch));
            ret = device_handle_wcdma_wirelessEn_request(DEV_OPCODE_SET, (atoi(conf->capWcdma.enable) == 1) && (atoi(conf->dev.RFSwitch) == 1) , buf, dcode);
            break;

        case REQUEST_WCDMA_REBOOT:
            ret = device_handle_reboot_wcdma(buf, dcode);
            break;

        case REQUEST_UPDATA_TDSCDMA:
            ret = device_handle_tdscdma_request(DEV_OPCODE_SET, 0, &conf->capTdscdma.tdscdma, buf, dcode);
            break;       

        case REQUEST_UPDATA_TDSCDMA_ENABLE:
            ret = device_handle_tdscdma_wirelessEn_request(DEV_OPCODE_SET, (atoi(conf->capTdscdma.enable) == 1) && (atoi(conf->dev.RFSwitch) == 1) , buf, dcode);
            break;    

        case REQUEST_TDSCDMA_REBOOT:
            ret = device_handle_reboot_tdscdma(buf, dcode);
            break;

        case REQUEST_UPDATA_WIFI_CFG:
            ret = device_handle_wifi_config_request(DEV_OPCODE_SET, atoi(conf->capWifi.intvl), buf, dcode);
            break;

        case REQUEST_UPDATA_WIFI_REDET:
            ret = device_handle_wifi_update_redet(atoi(conf->capWifi.intvl), buf, dcode);
            break;


        case REQUEST_EUTRAN_MANUAL_SNIFFER:
            ret = device_handle_eutran_sniffer_request(0, buf, dcode);
            break;
            
        case REQUEST_BBU1_INIT_CONFIG:
        case REQUEST_BBU2_INIT_CONFIG:
        case REQUEST_BBU3_INIT_CONFIG:
        case REQUEST_BBU4_INIT_CONFIG:
        case REQUEST_BBU5_INIT_CONFIG:
        case REQUEST_BBU6_INIT_CONFIG:
        case REQUEST_BBU7_INIT_CONFIG:
            ret = device_handle_eutran_init(&conf->capLte.lte[(type - REQUEST_BBU1_INIT_CONFIG)], conf->workMode.workMode, (type - REQUEST_BBU1_INIT_CONFIG + 1), buf, dcode);

            break;

        case REQUEST_BBU_TX_POWER1:
        case REQUEST_BBU_TX_POWER2:
        case REQUEST_BBU_TX_POWER3:
        case REQUEST_BBU_TX_POWER4:
        case REQUEST_BBU_TX_POWER5:
        case REQUEST_BBU_TX_POWER6:
        case REQUEST_BBU_TX_POWER7:
            ret = device_handle_eutran_pagain_config(conf->pa[(type - REQUEST_BBU_TX_POWER1) ].gain, (type - REQUEST_BBU_TX_POWER1 + 1),  atoi(conf->pa[(type - REQUEST_BBU_TX_POWER1) ].enable), atoi(conf->workMode.workMode), atoi(conf->dev.RFSwitch),  true, buf, dcode);
            break;

        case REQUEST_LTE_OPEN_ALL_POWER:
            ret = device_handle_eutran_pagain_config(conf->pa[par[0] -1].gain, par[0],  atoi(conf->pa[(par[0] - 1) ].enable), atoi(conf->workMode.workMode), atoi(conf->dev.RFSwitch),  false, buf, dcode);
            break;
            

        case REQUEST_BBU1_RSSI_CONFIG:
        case REQUEST_BBU2_RSSI_CONFIG:
        case REQUEST_BBU3_RSSI_CONFIG:
        case REQUEST_BBU4_RSSI_CONFIG:
        case REQUEST_BBU5_RSSI_CONFIG:
        case REQUEST_BBU6_RSSI_CONFIG:
        case REQUEST_BBU7_RSSI_CONFIG:
            ret = device_handle_eutran_config_rssi((type - REQUEST_BBU1_RSSI_CONFIG + 1), "60", buf, dcode);
            break;
        case REQUEST_SET_VAILD_PA:
            ret = device_init_vaild_pa(conf, atoi(conf->dev.devtype),  buf, dcode);
            break;

        case REQUEST_MANUAL_REBOOT_BBU:
            ret = device_handle_power_restart(par[0], buf, dcode);
            break; 

        case REQUEST_EUTRAN_CONFIG_CELL:
            ret = device_handle_eutran_config_cell(par[0], conf, buf, dcode);     
            break;

        case REQUEST_EUTRAN_UPDATA_CELL:
            ret = device_handle_eutran_update_cell(par[0], conf, buf, dcode);
            break;


        case REQUEST_EUTRAN_BBU_SYNC_MODE:
            ret = device_handle_setting_eutran_sync_mode((I8 *)data, buf, dcode);
            break;

        case REQUEST_EUTRAN_BBU_UPGRADE:
            ret = device_handle_eutran_bbu_upgrade(par[0], conf->capLte.lte[par[0] - 1].desc, buf,  dcode);
            break;
  
        case REQUEST_EUTRAN_BBU_REBOOT:
            ret = device_handle_eutran_bbu_reboot(par[0], buf, dcode);
            break;

        case REQUEST_EUTRAN_TX_POWER_CONFIG:
            ret = device_handle_eutran_txPower_config(conf->pa[par[0] -1 ].gain, par[0],   atoi(conf->pa[par[0] -1 ].enable), buf, dcode);
            break;

        case REQUEST_SHUTDOWN_ALLPOWER:
            ret = device_handle_eutran_txPower_config(conf->pa[par[0] -1 ].gain, par[0], 0, buf, dcode);
            break;

        case REQUEST_UPDATA_SHUTDOWN_TX_POWER:
            ret = device_handle_eutran_txPower_config(conf->pa[ cmdList.commandList[cmdList.cmdIndex -1].cellId -1 ].gain,  cmdList.commandList[cmdList.cmdIndex -1].cellId, 0, buf, dcode);
            break;
         

        case REQUEST_EUTRAN_BBU_SET_IP:
            ret = device_handle_eutran_set_bbuIp((I8 *)data, buf, dcode);
            break;

        case REQUEST_EUTRAN_STOP_SNIFFER:
            ret = device_handle_eutran_stop_sniffer(buf, dcode);
            break;

        case REQUEST_EUTRAN_RESET_SNIFFER:
            ret = device_handle_eutran_reset_sniffer(buf, dcode);
            break;

        case REQUEST_EUTRAN_BBU_STATE:
            ret = device_handle_eutran_bbu_state(buf, par[0], dcode);
            break;

        case REQUEST_EUTRAN_SHOW_BBU_INFO:
            ret = device_handle_eutran_show_bbu_info(buf, dcode);
            break;
  
        case REQUEST_EUTRAN_GET_BBU_SYNC:
            ret = device_handle_get_eutran_sync(par[0],  buf, dcode);
            break;
 
        case REQUEST_EUTRAN_SOFTWARE_VERSION:
            ret = device_handle_eutran_software_version(buf, par[0], dcode);
            break;

        case REQUEST_EUTRAN_GET_SNIFFER_STATUS:
            ret = device_handle_eutran_get_sniffer_status((I8 *)data, buf, dcode);
            break;
  
        case REUQEST_EUTRAN_GET_SNIFFER_RESULT:
            ret = device_handle_eutran_get_sniffer_result(buf, dcode);
            break;

        case REQUEST_EUTRAN_GET_RSSI:
            ret = device_handle_eutran_get_rssi(buf, dcode);
            break;

        case REQUEST_UE_REDIRECT_ON:
            ret = device_handle_ue_redirect(1, (I8 *)data, buf, dcode);
            break;

        case REQUEST_UE_REDIRECT_OFF:
            ret = device_handle_ue_redirect(2, (I8 *)data, buf, dcode);
            break;

        case REQUEST_UPDATA_TX_POWER:
            ret =  device_handle_eutran_pagain_config(conf->pa[cmdList.commandList[cmdList.cmdIndex -1].cellId -1].gain, cmdList.commandList[cmdList.cmdIndex -1].cellId,  atoi(conf->pa[cmdList.commandList[cmdList.cmdIndex -1].cellId - 1].enable), atoi(conf->workMode.workMode), atoi(conf->dev.RFSwitch), false, buf, dcode);
            break;

        case REQUEST_SET_BLACKLIST_ON:
             ret = device_handle_set_blackList_on((I8 *)data, buf, dcode);
             break;


        case REQUEST_UE_FILTER_ON:
            ret = device_handle_set_ue_filter(1, data, buf, dcode);
            break;

        case REQUEST_UE_FILTER_OFF:
            ret = device_handle_set_ue_filter(0, data, buf, dcode);
            break;

        case REQUEST_BBU_RADIO_OFF:
            ret = device_handle_eutran_set_work_period(1, buf, dcode);
            break;

        case REQUEST_BBU_RADIO_ON:
            ret = device_handle_eutran_set_work_period(0, buf, dcode);
            break;

        case REQUEST_UPDATA_SMS_SND:
            ret = device_handle_sms_snd((I8 *)data, buf, dcode);
            break;

        case REQUEST_UPDATA_SMS_MSG:
            ret  = device_handle_sms_msg(atoi(conf->sms.msgEnable), buf, dcode);
            break;
        
        case REQUEST_UPDATA_SMS_KEY:
            ret = device_handle_sms_key(conf->sms.smsKey, buf, dcode);
            break;

        case REQUEST_SET_UPLOAD_MODE:
            ret = device_handle_set_upload_mode(DEV_OPCODE_SET, atoi(conf->dev.uploadMode), buf, dcode);
            break;

        case REQUEST_FTP_REPORT_DATA_ON:
            ret = device_handle_set_upload_mode(DEV_OPCODE_SET, 0, buf, dcode);
            break;

        case REQUEST_FTP_REPORT_DATA_OFF:
            ret = device_handle_set_upload_mode(DEV_OPCODE_SET, 2, buf, dcode);
            break;


        case REQUEST_SR_GPSINFO:
            ret = device_handle_gps_request(par[0], buf, dcode);
            break;

        case REQUEST_ADD_BLACKLIST:
            ret = device_handle_update_blackList((I8 *)data, 1, buf, dcode);
            break;

        case REQUEST_DEL_BLACKLIST:
            ret = device_handle_update_blackList((I8 *)data, 0, buf, dcode);
            break;
        

        case REQUEST_ADD_WHITELIST:
            ret = device_handle_update_whiteList((I8 *) data, 1, buf, dcode);
            break;

        case REQUEST_DEL_WHITELIST:
            ret = device_handle_update_whiteList((I8 *) data, 0, buf, dcode);
            break;

        case REQUEST_UPDATA_REBOOT:
            ret = device_handle_reboot_request(par[0], buf, dcode);
            break;

        case REQUEST_UPDATA_SMS:
            ret = device_handle_smsEn_request(DEV_OPCODE_SET, atoi(conf->sms.enable), atoi(conf->workMode.workMode) , buf, dcode);
            break;

        case REQUEST_UPDATA_SYS_RBEOOT:
            ret = device_handle_set_sys_reboot(DEV_OPCODE_SET, conf->restart, buf, dcode);
            break;

        case REQUEST_UPDATA_TIME:
            ret = device_handle_time_sync_request(par[0], buf, dcode);
            break;

        case REQUEST_UPDATA_SLEEP:
            ret = device_handle_sleep(buf, dcode);
            break;

        case REQUEST_UPDATA_WAKEUP:
            ret = device_handle_wakeup(buf, dcode);
            break;

        case REQUEST_FACTORY_DEFAULT:
            ret = device_handle_factory_reset(buf, dcode);
            break;

        case REQUEST_UPDATE_GET_DATA:
            ret = device_handle_get_data(par[0], par[1], buf, dcode);
            break;

        case REQUEST_UPDATA_IND_ACK:
            ret = device_handle_updata_ack(buf, dcode);
            break;

        case REQUEST_UPDATA_STOP:
            ret = device_handle_get_data_stop(buf, dcode);
            break;

        case REQUEST_GET_STATUS:
            ret = device_handle_get_satus(buf, dcode);
            break;

        case REQUEST_UPDATA_STORAGE:
            ret = device_handle_update_storage(atoi(conf->storage.peroid), buf, dcode);
            break;

        case REQUEST_SOFTWARE_UPDATA:
            ret = device_handle_software_update((I8 *) data, buf, dcode);
            break;

		case REQUEST_GET_SYS_INFO:
			ret = device_handle_get_sys_info(buf, dcode);
			break;

        case REQUEST_UPGRADE_X86:
            ret = device_handle_upgrade_x86(buf, dcode);
            break;

        case REQUEST_CLEAN_DATA:
            ret = device_handle_clean_data(buf, dcode);
            break;

        case REQUEST_REBOOT_DEVICE:
            ret = device_handle_pm_reboot_device(buf, dcode);
            break;

        case REQUEST_SR_DEVICE_LOG:
            ret = device_handle_system_collect_log(buf, dcode);
            break;

        case REQUEST_INTERNAL_HEARTBEAT:
            ret = device_handle_internal_heartbeat(par[0], buf, dcode);
            break;

        case REQUEST_SR_BLACKLIST:
            ret = device_handle_sr_blackList(true, buf, dcode);
            break;
            
        case REQUEST_SR_BLACKLIST_STOP:
            ret = device_handle_sr_blackList(false, buf, dcode);
            break;

        case REQUEST_SR_BLACKLIST_INACK:
            ret = device_handle_sr_blackList_inack(buf, dcode);
            break;
        
        case REQUEST_PA_POWER_ON:
            ret = device_handle_set_pa_power(true, par[0], buf, dcode);
            break;

        case REQUEST_PA_POWER_OFF:
            ret = device_handle_set_pa_power(false, par[0], buf, dcode);
            break;
        
        case REQUEST_LTE_SNIFFER:
            ret = device_handle_lte_and_wcdma_manual_sniffer(CMD_LTE_DO_SNIFFER, buf, dcode);
            break;


        case REQUEST_WCDMA_SNIFFER:
            ret = device_handle_lte_and_wcdma_manual_sniffer(CMD_WCDMA_DO_SNIFFER, buf, dcode);
            break;
        
        case REQUEST_REMOTE_SSH_ON:
            ret = device_handle_remote_ssh_on((REMOTE_SSH *)data, buf, dcode);
            break;

        case REQUEST_REMOTE_SSH_OFF:
            ret = device_handle_remote_ssh_off(buf, dcode);
            break;
			
		case REQUEST_EUTRAN_BBU_SCAN_ON:
			ret = device_handle_set_bbu_scan(par[0], buf, dcode);
			break; 

        case REQUEST_EUTRAN_BBU_SCAN_OFF:
             ret = device_handle_set_bbu_scan(0, buf, dcode);
             break;

		case REQUEST_TDD_LOCATION_ON:
			ret = device_handle_set_location_on(1, (I8 *)data, buf, dcode);
			break;

		case REQUEST_TDD_LOCATION_OFF:
			ret = device_handle_set_location_off(1, buf, dcode);
			break;

		case REQUEST_FDD_LOCATION_ON:
			ret = device_handle_set_location_on(0, (I8 *)data, buf, dcode);
			break;

		case REQUEST_FDD_LOCATION_OFF:
			ret = device_handle_set_location_off(0, buf, dcode);
			break;
		

		case REQUEST_FDD_MODE:
			ret = device_handle_chang_teleOperator(atoi(conf->dev.devtype), conf->capLte, buf, dcode);
			break;

        case REQUEST_SET_LOCATION_MODE:
            ret = device_handle_set_location_enable(buf, dcode);
            break;

        case REQUEST_REDIRECT_INIT_CONFIG:
            cli_app_log(CLI_LOG_NOTICE,"REQUEST_REDIRECT_INIT_CONFIG\n");
            //break;
            ret = device_handle_redirect_init(&conf->redirect[0], conf->workMode.workMode, buf, dcode);
            break;

		default:
			break;
    }

    return ret;
}

I32 device_handle_init_all(DEV_CONF * conf, I8 * buf, I32 * dcode)
{
    I32 ret = -1;
    dev_init_status++;




    if (dev_init_status >= TAG_REQUEST_BBU1_INIT_CONFIG && 
        dev_init_status <= TAG_REQUEST_BBU7_RSSI_CONFIG )
    {
        if (  atoi(conf->capLte.isSupported) == 1 )
        {
            if ((dev_init_status >= TAG_REQUEST_BBU1_INIT_CONFIG) && 
                (dev_init_status <= TAG_REQUEST_BBU7_INIT_CONFIG))
            {        
                while ((atoi(conf->capLte.lte[dev_init_status - TAG_REQUEST_BBU1_INIT_CONFIG].enable) == 0) && 
                       (dev_init_status <= TAG_REQUEST_BBU7_INIT_CONFIG))
                {    
                    dev_init_status++;
                }
            }
            if ((dev_init_status >= TAG_REQUEST_BBU_TX_POWER1) && 
                (dev_init_status <= TAG_REQUEST_BBU_TX_POWER7))
            {
                while ((atoi(conf->capLte.lte[dev_init_status - TAG_REQUEST_BBU_TX_POWER1].enable) == 0) &&
                       (dev_init_status <= TAG_REQUEST_BBU_TX_POWER7))
                {
                    dev_init_status++;
                }
            } 
            if ((dev_init_status >= TAG_REQUEST_BBU1_RSSI_CONFIG) && 
                (dev_init_status <= TAG_REQUEST_BBU7_RSSI_CONFIG))
            {
                while ((atoi(conf->capLte.lte[dev_init_status - TAG_REQUEST_BBU1_RSSI_CONFIG].enable) == 0) && 
                       (dev_init_status <= TAG_REQUEST_BBU7_RSSI_CONFIG))
                {
                    dev_init_status++;
                }
            }        
        }
        else
        {
            dev_init_status = TAG_REQUEST_UPDATA_GSM1;
        }
    }
    
    if ( dev_init_status >= TAG_REQUEST_UPDATA_GSM1 &&
         dev_init_status <= TAG_REQUEST_GSM_MANUAL_SNIFFER )
    {
        if ( dev_init_status == TAG_REQUEST_GSM_MANUAL_SNIFFER && atoi(conf->snfGsm.enable) == 0)
            dev_init_status  = TAG_REQUEST_UPDATA_CDMA;
        if ( atoi(conf->capGsm.isSupported) == 0 )
            dev_init_status  = TAG_REQUEST_UPDATA_CDMA;

    }

    if ( dev_init_status >= TAG_REQUEST_UPDATA_CDMA && 
         dev_init_status <= TAG_REQUEST_UPDATA_CDMA_WIFI )
    {
        if ( atoi(conf->capCdma.isSupported) == 0 )
            dev_init_status  = TAG_REQUEST_UPDATA_WCDMA;
    }

    if ( dev_init_status >= TAG_REQUEST_UPDATA_WCDMA && 
         dev_init_status <= TAG_REQUEST_UPDATA_WCDMA )
    {
        if ( atoi(conf->capWcdma.isSupported) == 0 )
            dev_init_status  = TAG_REQUEST_UPDATA_TDSCDMA;
    }

    if ( dev_init_status >= TAG_REQUEST_UPDATA_TDSCDMA && 
         dev_init_status <= TAG_REQUEST_UPDATA_TDSCDMA )
    {
        if ( atoi(conf->capTdscdma.isSupported) == 0 )
            dev_init_status  = TAG_REQUEST_UPDATA_WIFI_CFG;
    }



    if ( dev_init_status >= TAG_REQUEST_UPDATA_WIFI_CFG && 
         dev_init_status <= TAG_REQUEST_UPDATA_WIFI_CFG)
    {
        if ( atoi(conf->capWifi.isSupported) == 0 )
            dev_init_status  = DEV_INIT_STAT_LAST;
    }

   

    cli_app_log(CLI_LOG_NOTICE, "INIT NUM IS %d \n", dev_init_status);
   // cli_app_log(CLI_LOG_NOTICE, "allModuleInit[dev_init_status ] 0x%x %d\n", allModuleInit[dev_init_status ], TAG_REQUEST_REDIRECT_INIT_CONFIG);
    if ( dev_init_status < TAG_REQUEST_UPDATA_DONE)
        ret = device_handle_request(allModuleInit[dev_init_status ], conf, buf, NULL, dcode);
    else
        dev_init_status  = DEV_INIT_STAT_LAST;
    return ret;
}

I32 device_get_init_status()
{
    return dev_init_status;
}

I32 device_set_init_state(I32 state)
{
    dev_init_status = state;

    return 0;
}

static I32 device_get_tlv(I32 * buf, I32 buf_len, I32 type, I32 ** par,
                          I32 * par_len)
{
    TLV_S *tmp;
    I32 total_len = 0, len = 0;
    I32 ret = IF_APP_ERROR;

    while (buf_len > total_len) {
        tmp = (TLV_S *) ((I8 *) buf + roundup8(total_len));
        len = tmp->len + (2 * sizeof(U32));

        total_len += roundup8(len);
	
        if (tmp->type == type) {
            *par = tmp->val;
            *par_len = tmp->len;
            ret = total_len;
            break;
        }
    }
	
    return ret;
}

short int UPDATE_GSM_RSSI = 0;
short int UPDATE_CDMA_RSSI = 0;
I32 device_handle_response(I8 * buf, I32 * data)
{
    DEV_CMD *cmd = (DEV_CMD *) buf;
    I32 ret = IF_APP_ERROR;
    DEV_SET_RSP *resp = (DEV_SET_RSP *) data;
    DEV_CONF *conf = (DEV_CONF *) (data + (sizeof(DEV_SET_RSP) / 4));
    SYS_INFO *sysInfo = (SYS_INFO *)(data +(sizeof(DEV_SET_RSP) / 4) );
    SOFTWARE_VERSION_INFO *Info = (SOFTWARE_VERSION_INFO *)(data +(sizeof(DEV_SET_RSP) / 4) );


    static U32 lastTm = 0;
    bool isLast = false;
    DELAY_REPORT *dreport= (DELAY_REPORT *) (data);
    DEV_STATUS *status = (DEV_STATUS *) conf;
    GPSINFO * gps_info = (GPSINFO *)conf;
    I32 *par = NULL, par_len = 0;
    I32 i, tmp, len, tmp1;
    I8 *tmp_data;
 
    if( cmd == NULL )
    {
        cli_app_log(CLI_LOG_ERROR, "%s, event buf is NULL\n", __func__);
        return ret;
    }
    cli_app_log(CLI_LOG_DEFAULT, "%s, cmd type=0x%04X code=0x%04X idx=%d len=%d\n", 
         __func__, cmd->cmdType, cmd->cmdCode, cmd->cmdIndex, cmd->cmdLength);

//  bzero(data, sizeof(DEV_CONF) + sizeof(DEV_SET_RSP));

    switch (cmd->cmdType) {
        case DEV_OPCODE_SET_RPL:
            // 2 tlvs max, each is 64bit
			  
            resp->id = cmd->cmdIndex;
            resp->dcode = cmd->cmdCode;
				
            ret = RESPONSE_SET_RESPONSE;	
            //dev side, should not be error.
            device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_RESULT, &par, &par_len);				
            resp->code = *par;
            if (resp->code == PARA_VALUE_RESULT_FAILED) {
                device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_ERROR_CODE, &par, &par_len);
                resp->errcode = *par;

            } else if (resp->code == PARA_VALUE_RESULT_SUCCESS) {                
                 if (cmd->cmdCode == CMD_CODE_SYS_UPGRADE)
                 {
                     if(device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_UPGRADE_TYPE, &par, &par_len) > 0)
                     {
                          resp->errcode = *par;
                          cli_app_log(CLI_LOG_INFO, "sysupgrade type is %d  \n", *par);
                     }

                 }
            }
		
            break;

        case DEV_OPCODE_GET_RPL:
            resp->id = cmd->cmdIndex;
            resp->dcode = cmd->cmdCode;

            switch (resp->dcode) {
                case CMD_CODE_SYS_STATUS:
                    len = 0;
                    len += device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_CPU_USAGE, &par, &par_len);
                    dev_status.cpu_load = *par;
                    len += device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_MEM_USAGE, &par, &par_len);
                    dev_status.mem_load = *par;
                    len += device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_DATA_STORAGE_USAGE, &par, &par_len);
                    dev_status.disk_usage = *par;
                    len += device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_TEMPERATURE, &par, &par_len);
                    dev_status.board_tmp = *par;
                
                    len += device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_GSM_WILELESS_STATE, &par, &par_len);
                    dev_status.gsm_status = *par;
                    len += device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_GSM_SNIFFER_STATE, &par, &par_len);
                    status->snf_status = *par;

                    len += device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_GPS_STATUS, &par, &par_len);
                    
                    len += device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_GPS_COORDINATE, &par, &par_len);
                    
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_PASTATUS, &par, &par_len);
                     
                    tmp_data= (I8 *)par;
                    for (tmp1 =0; tmp1 < 11 ; tmp1++)
                    {
                       memcpy((I8  *)(&dev_status.pa_status[tmp1]), tmp_data, sizeof(PA_STATUS));
                       cli_app_log(CLI_LOG_INFO, "pa[%d] tmp  %d \n", tmp1+1, dev_status.pa_status[tmp1].temp);
                       tmp_data += sizeof(PA_STATUS);
                    }

                    ret = IF_APP_REP_STATUS | RESPONSE_GET_RESPONSE;
                    break;

				case CMD_CODE_BASIC_INFO:
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_MAC_ADDR, &par, &par_len);
                    if(par != NULL) {
                        tmp_data = (I8 *)par; 
                        len = sprintf((I8 *)(sysInfo->mac_addr), "%02X:%02X:%02X:%02X:%02X:%02X", (U8)tmp_data[0], (U8)tmp_data[1], 
									  (U8)tmp_data[2], (U8)tmp_data[3], (U8)tmp_data[4], (U8)tmp_data[5]);
						
                    } else {
                        len = sprintf((I8 *)(sysInfo->mac_addr), "%02X:%02X:%02X:%02X:%02X:%02X", 
                          0, 0, 0, 0, 0, 0);					
                    }
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_DEVICE_TYPE, &par, &par_len);
                    memcpy(sysInfo->dev_type, (I8 *)par, par_len);
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_SW_VERSION, &par, &par_len);
                    memcpy(sysInfo->sw_version, (I8 *)par, par_len);
                    memcpy(devVersion.version,  (I8 *)par, par_len);
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_SW_BUILDDATE, &par, &par_len);
                    memcpy(sysInfo->build_date, (I8 *)par, par_len);
                    memcpy(devVersion.buildDate, (I8 *)par, par_len);
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_SW_BUILDTIME, &par, &par_len);
                    memcpy(sysInfo->build_time, (I8 *)par, par_len);
                    memcpy(devVersion.buildTime, (I8 *)par, par_len);
                    cli_app_log(CLI_LOG_NOTICE, "system builddate is %s system buildTime is %s \n", devVersion.buildDate, devVersion.buildTime);
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_SW_COMPILER_VERSION, &par, &par_len);
                    memcpy(sysInfo->compliter_verison, (I8 *)par, par_len);
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_OS_VERSION, &par, &par_len);
                    memcpy(sysInfo->os_version, (I8 *)par, par_len);
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_HW_VERSION , &par, &par_len);
                    memcpy(sysInfo->hw_version, (I8 *)par, par_len);
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_SW_ORIGINAL_VERSION , &par, &par_len);
                    memcpy(sysInfo->sw_originalVer, (I8 *)par, par_len);
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_SW_CURRVERNUM  , &par, &par_len);
                    memcpy(sysInfo->currVernum, (I8 *)par, par_len);
                    
                    ret = IF_APP_REP_SYSINFO | RESPONSE_GET_RESPONSE;
                    break;


                case CMD_CODE_EUTRAN_GPS_STATE_REQ:
#ifdef	MODULE_GPS_BOARD
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_RESULT, &par, &par_len);				
                    resp->code = *par;
                    cli_app_log(CLI_LOG_INFO , "BBU STATE result %08x \n", resp->code);

                    if (resp->code == PARA_VALUE_RESULT_SUCCESS)
                    {
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_GPS_LONGTITUDE, &par, &par_len);
                        gpsboardinfo.longitude = (float)*par/100000;
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_GPS_LATITUDE, &par, &par_len);
                        gpsboardinfo.latitude = (float)*par/100000 ;
						device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_GPS_STARCNT, &par, &par_len);
						gpsboardinfo.starcnt = *par;
                    }
#else				
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_RESULT, &par, &par_len);				
                    resp->code = *par;
                    cli_app_log(CLI_LOG_INFO , "BBU STATE result %08x \n", resp->code);

                    if (resp->code == PARA_VALUE_RESULT_SUCCESS)
                    {
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_GPS_LONGTITUDE, &par, &par_len);
                        gps_info->longitude = (float)*par/100000;
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_GPS_LATITUDE, &par, &par_len);
                        gps_info->latitude = (float)*par/100000 ;
                    }
#endif
                    else
                    {
                        gps_info->longitude = 0;
                        gps_info->latitude = 0;
                        gps_info->altitude = 0;
                    }
                    ret = IF_APP_SR_GPSINFO | RESPONSE_GET_RESPONSE;
                    break;


                case CMD_GSM_GET_VERSION:
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_RESULT, &par, &par_len) != IF_APP_ERROR)
                    {
                        strcpy((I8 *)conf, "  ");

                    }
                    else if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_GSM_VERSION, &par, &par_len) != IF_APP_ERROR)
                    {
                        memcpy((I8 *)conf, (I8 *)&par[0], par_len);
                    }

                    ret = IF_APP_SR_VERSION | RESPONSE_GET_RESPONSE;
                    break;
                    
                case CMD_CODE_EUTRAN_BBU_STATE_REQ:
                 
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_RESULT, &par, &par_len);				
                    resp->code = *par;
                    cli_app_log(CLI_LOG_INFO , "BBU STATE result %08x \n", resp->code);

                    if (resp->code == PARA_VALUE_RESULT_SUCCESS)
                    {
                        
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_SLOT_ID, &par, &par_len);
                        resp->errcode = *par;
                        
                       
                        BBU_STATUS *bbuStatus = (BBU_STATUS *)conf;
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_STATE, &par, &par_len);

                        
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_MEM_USAGE, &par, &par_len);
                    
                        bbuStatus->memusage = *par;
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_CPU_USAGE, &par, &par_len);
                    
                        bbuStatus->cpuusage = *par;
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_CPU_TEMP, &par, &par_len);
                      
                        bbuStatus->cputemp = *par;
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BOARD_TEMP, &par, &par_len);
                       
                        bbuStatus->boardtemp = *par;
                        cli_app_log(CLI_LOG_INFO, " BBU[%d]  MEM USAGE is %d CPU USAGE == %d CPU TEMP ==== %d BOARD TEMP ==== %d \n" ,
                                                   resp->errcode, bbuStatus->memusage, bbuStatus->cpuusage, bbuStatus->cputemp, bbuStatus->boardtemp);
                    }
                    ret = IF_APP_SR_BBU_STATE | RESPONSE_GET_RESPONSE;
                    break;

                case CMD_CODE_EUTRAN_SOFTWARE_VERSION_REQ:
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_RESULT, &par, &par_len);				
                    resp->code = *par;


                    if (resp->code == PARA_VALUE_RESULT_SUCCESS)
                    {
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_SLOT_ID, &par, &par_len);
                        Info->slotId = *par;
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_SOFTWARE_VERSION, &par, &par_len);
                                   
                        strcpy(Info->software_version, par_len>0?(I8 *)par:" ");

                    }
                    ret = IF_APP_SR_EUTRAN_VERSION | RESPONSE_GET_RESPONSE;
                    break;
            
            
 
               case CMD_CODE_EUTRAN_SYNC_STATE_GET:

                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_RESULT, &par, &par_len);				
                    resp->code = *par;


                    if (resp->code == PARA_VALUE_RESULT_SUCCESS)
                    {
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_SLOT_ID, &par, &par_len);
                        resp->errcode = *par;
                        BBU_STATUS *bbuStatus = (BBU_STATUS *)conf;                        
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_SYNC_STATE_TYPE_CODE, &par, &par_len);
                        bbuStatus->syncType = *par;
                        
                        device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_SYNC_STATE_CODE, &par, &par_len);
                        bbuStatus->syncState = *par;
                       
                        cli_app_log(CLI_LOG_INFO, "BBU[%d] SYNCTYPE %d SYNC STATE CODE %d \n", resp->errcode, bbuStatus->syncType, bbuStatus->syncState);

                    }
                    ret = IF_APP_BBU_SYNC_STATE |RESPONSE_GET_RESPONSE;
                    break;
                    


               case CMD_CODE_EUTRAN_SHOW_BBU_INFO:
                    
                    device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_INFO_STR, &par, &par_len);
                    resp->code = PARA_VALUE_RESULT_FAILED;
                    {
                     I32 tmp2 =0;
                     char bufTmp[24];
                     char *str_tmp = (I8 *) & par[0];
                     tmp1 = 0;
                     tmp = 0;
                     i = 0;
                     if (par_len > 0)
                         resp->code = PARA_VALUE_RESULT_SUCCESS;
                     while(par_len > 0)
                     {
                        while(*(char *)str_tmp != '\n')
                        {

                            if (tmp == 1)
                                i ++;
                            if (*(char *)str_tmp == '[')
                               tmp = 1;
                         
                            if (*(char *)str_tmp == ']')
                            {   
                                
                                tmp = 0;
                                memset(bufTmp, 0, 24);
                                i -= 1;
                                memcpy(bufTmp, str_tmp -i, i);
                                if (tmp2 == 2)
                                {
                                    if (strcmp(bufTmp, "Deactive") == 0)
                                     ; // strcpy(conf->cap1.lte[tmp1].enable, "0"); 
                                    else 
                                     ; // strcpy(conf->cap1.lte[tmp1].enable, "1"); 

                                }
                         
                                i = 0;
                                tmp2++;
                            }
                            str_tmp++;
                            par_len--;

                        }
                        tmp2 = 0;
                        tmp1 ++; 
                        str_tmp++;
                        par_len--;
  
                     }                    
                   }

                        
                    ret = IF_APP_EUTRAN_BBU_INFO | RESPONSE_GET_RESPONSE;
                     break;                 

           }

            break;

        case DEV_OPCODE_IND:

            resp->id = cmd->cmdIndex;
            resp->dcode = cmd->cmdCode;

            ret = RESPONSE_IND_RESPONSE;

            switch (cmd->cmdCode) {
                case CMD_CODE_PHONE_INFO_DATA:
                    //should be OK,  PARA_TYPE_DATASTOR_HAS_MORE_DATA is always in this indication.
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_DATASTOR_HAS_MORE_DATA, &par, &par_len) != IF_APP_ERROR) {

                        PHONE_DATA *phone;
                        if (*par == 0) {
                            ret = IF_APP_DATA_END | RESPONSE_IND_RESPONSE;
                        } else {
                            ret = IF_APP_DATA_CONTINUE | RESPONSE_IND_RESPONSE;
                        }
                        cli_app_log(CLI_LOG_INFO,
                                    "ret in DEV_OPCODE_IND is %08x\n", ret);

                        i = 0;
                        tmp_data = (I8 *) cmd->data;
                        len = cmd->cmdLength;
                        phone = (PHONE_DATA *) & data[1];
                        while (len) {
                            tmp = device_get_tlv((I32 *) tmp_data, len, PARA_TYPE_DATASTOR_PHONE_INFO, &par, &par_len);
                            if (tmp != IF_APP_ERROR) {
                                char *str_tmp = (I8 *) & par[3];
                                phone->time_low = par[0];
                                phone->time_high = par[1];
                               
 
                                phone->slotId = par[2];
                               
                                //make sure slotId  not error
                                if ( i == 0)
                                { 
                                    if (lastTm != phone->time_low)
                                    {
                                        lastTm = phone->time_low;
                                        isLast = true;
                                        
                                    }      
                                }

                                if ((phone->slotId <= 7) && isLast)
                                    slotNum[phone->slotId -1]++;
                                strcpy((I8 *) phone->imsi, str_tmp);
                                str_tmp += strlen(str_tmp) + 1;
                                strcpy((I8 *)phone->imei, str_tmp);
                            
                                str_tmp += strlen(str_tmp) + 1;
                                strcpy((I8 *) phone->tmsi, str_tmp);
                                cli_app_log(CLI_LOG_DEFAULT, "slotid[%d] imsi:%s \n", phone->slotId, (I8 *) phone->imsi);
                                phone++;
                                i++;
                                tmp_data += tmp;
                                len -= tmp;
                            } else
                                break;
                        }
                        data[0] = i;
                        cli_app_log(CLI_LOG_INFO,
                                    "Get %d phone data from device\n", i);
                    }
                    break;

                case CMD_CODE_BLACKLIST_IMSI_DATA:
                    //should be OK,  PARA_TYPE_DATASTOR_HAS_MORE_DATA is always in this indication.
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_DATAPROC_HAS_MORE_DATA, &par, &par_len) != IF_APP_ERROR) {

                        PHONE_DATA *phone;
                        if (*par == 0) {
                            ret = IF_APP_BLACKLIST_END | RESPONSE_IND_RESPONSE;
                        } else {
                            ret = IF_APP_BLACKLIST_CONTINUE | RESPONSE_IND_RESPONSE;
                        }
                        cli_app_log(CLI_LOG_INFO,
                                    "ret in DEV_OPCODE_IND is %08x\n", ret);

                        i = 0;
                        tmp_data = (I8 *) cmd->data;
                        len = cmd->cmdLength;
                        phone = (PHONE_DATA *) & data[1];
                        while (len) {
                            tmp = device_get_tlv((I32 *) tmp_data, len, PARA_TYPE_DATAPROC_RECORD_IMSI, &par, &par_len);
                            if (tmp != IF_APP_ERROR) {
                                char *str_tmp = (I8 *) & par[0];
                                strcpy((I8 *) phone->imsi, str_tmp);
                                str_tmp += strlen(str_tmp) + 1;
                            
                                cli_app_log(CLI_LOG_DEFAULT, "black imsi:%s \n", (I8 *) phone->imsi);
                                phone++;
                                i++;
                                tmp_data += tmp;
                                len -= tmp;
                            } else
                                break;
                        }
                        data[0] = i;
                        cli_app_log(CLI_LOG_INFO,
                                    "Get %d black phone data from device\n", i);
                    }
                    break;

                case CMD_CODE_DATAPRO_PHONE_INFO:
                     {  
                        PHONE_DATA *phone;
     
                        ret = IF_APP_DATA_EVENT | RESPONSE_IND_RESPONSE;
                    

                        i = 0;
                        tmp_data = (I8 *) cmd->data;
                        len = cmd->cmdLength;
                        phone = (PHONE_DATA *) & data[1];
                        while (len) {
                            tmp = device_get_tlv((I32 *) tmp_data, len, PARA_TYPE_DATAPROC_PHONE_INFO, &par, &par_len);
                            if (tmp != IF_APP_ERROR) {
                                char *str_tmp = (I8 *) & par[3];
                                phone->time_low = par[0];
                                phone->time_high = par[1];
                               
 
                                phone->slotId = (par[2]) & 0xff;
                                phone->lac = (par[2] >> 16 )& 0xff;
                                //make sure slotId  not error
                                if ( i == 0)
                                { 
                                    if (lastTm != phone->time_low)
                                    {
                                        lastTm = phone->time_low;
                                        isLast = true;
                                        
                                    }      
                                }
                                if ((phone->slotId <= 7) && isLast)
                                    slotNum[phone->slotId -1]++;
                                strcpy((I8 *) phone->imsi, str_tmp);
                                str_tmp += strlen(str_tmp) + 1;
                                strcpy((I8 *)phone->imei, str_tmp);
                            
                                str_tmp += strlen(str_tmp) + 1;
                                strcpy((I8 *) phone->tmsi, str_tmp);
                                cli_app_log(CLI_LOG_DEFAULT, "SLOT[%d] IMSI:%s LAC:%d\n",  phone->slotId, phone->imsi, phone->lac);
                                phone++;
                                i++;
                                tmp_data += tmp;
                                len -= tmp;
                            } else
                                break;
                        }
                        data[0] = i;
                        cli_app_log(CLI_LOG_INFO,
                                    "recv %d phone data from device\n", i);
                    }
                     break;

                case CMD_CODE_DATAPRO_MAC_INFO:
                    {
                        MAC_DATA *mac;
                        i = 0;
                        ret = IF_APP_MAC_EVENT | RESPONSE_IND_RESPONSE;
                        tmp_data = (I8 *) cmd->data;
                        len = cmd->cmdLength;
                        mac = (MAC_DATA *) & data[1];
                        while (len) {
                            tmp = device_get_tlv((I32 *) tmp_data, len, PARA_TYPE_WIFI_MAC_REPORT, &par, &par_len);
                            if (tmp != IF_APP_ERROR) {
                                char *str_tmp = (I8 *) & par[2];
                                mac->time_low = par[0];
                                mac->time_high = par[1];
                                memcpy((I8 *) mac->mac, str_tmp, 12);
                                mac->mac[12]='\0';
                                cli_app_log(CLI_LOG_DEFAULT, "time[%d] mac:%s \n",  mac->time_low, (I8 *) mac->mac);
                                mac++;
                                i++;
                                tmp_data += tmp;
                                len -= tmp;
                            } else
                                break;
                        }
                        data[0] = i;
                        cli_app_log(CLI_LOG_INFO,
                                    "recv %d mac data from device\n", i);
                    }
                    break;


                case CMD_EVT_EUTRAN_SNIFFER_RESULT:
                    ret |= IF_APP_SNF_RSLT;
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_SLOT_ID, &par, &par_len) != IF_APP_ERROR) {
                        data[0] = *par;
                    }
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SNIFFER_BUSY, &par, &par_len) != IF_APP_ERROR) {
                        data[1] = IF_APP_ERROR;
                    } else if (device_get_tlv(cmd->data, cmd->cmdLength,PARA_TYPE_EUTRAN_SNIFFER_EMPTY_RESULT, &par, &par_len) != IF_APP_ERROR) {
                        data[1] = 0;
                    } else
                        if (device_get_tlv (cmd->data, cmd->cmdLength,PARA_TYPE_EUTRAN_SNIFFER_RESULT, &par, &par_len) != IF_APP_ERROR) {
                        data[1] = par_len / sizeof(SNF_RSLT);
                        memcpy(&data[2], par, par_len);
                        SNF_RSLT *snfrst= (SNF_RSLT *)(data + 2);
                        for (tmp = 0; tmp < data[1]; tmp++)
                        { 
                            cli_app_log(CLI_LOG_INFO, "snf result freq=%d; pci= %d; tac=%d; rssi=%d priority=%d\n", snfrst[tmp].freq, snfrst[tmp].pci, snfrst[tmp].tac, snfrst[tmp].rssi, snfrst[tmp].priority);

                        }
                    }

                    break;


                case CMD_EVT_EUTRAN_BBU_STATE:
                    ret |= IF_APP_BBU_STATE;
         
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_SLOT_ID, &par, &par_len) != IF_APP_ERROR) {
                        data[0] = *par;
                    }
                    
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_STATE, &par, &par_len) != IF_APP_ERROR) {
                        data[1] = *par;
                    }
                    cli_app_log(CLI_LOG_INFO, "bbu === %d state ============ %d \n", data[0], data[1]);
                    break;

                case CMD_EVT_EUTRAN_REPORT_BBU_EARFCN:
                    ret |= cmd->cmdCode;         
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_SLOT_ID, &par, &par_len) != IF_APP_ERROR) {
                        data[0] = *par;
                    }
                    
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_DL_ARFCN, &par, &par_len) != IF_APP_ERROR) {
                        data[1] = *par;
                    }
                    cli_app_log(CLI_LOG_INFO, "bbu === %d EARFCN ============ %d \n", data[0], data[1]);
                    break;
                    

                case CMD_EVT_EUTRAN_NOT_RECV_IMSI:
                    ret |= cmd->cmdCode;
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_SLOT_ID, &par, &par_len) != IF_APP_ERROR) {
                        data[0] = *par;
                    }
                    cli_app_log(CLI_LOG_WARNING, "can not recv imis bbu is %d \n", data[0]);
                    break;

                case CMD_GSM_EVT_SNIFF:
                    ret |= IF_APP_GSM_SNIFF;
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SNIFFER_RESULT, &par, &par_len) != IF_APP_ERROR)
                    {
                        memcpy(&data[0], (I8 *)par, par_len);
                        ((I8 *)data)[par_len] = '\0';
                        cli_app_log(CLI_LOG_INFO, "gsm sniffer result is %s \n", (I8 *)par);
                    }
                    else
                    {
                        strcpy((I8 *)data, "");
                    }
                    break;
                    
                case CMD_EVT_EUTRAN_RSSI:
                    ret |= cmd->cmdCode;
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_GSM_SNIF_RSSI, &par, &par_len) != IF_APP_ERROR)
                    {
                        //memcpy(&data[0], (I8 *)par, par_len);
                        //((I8 *)data)[par_len] = '\0';
                        UPDATE_GSM_RSSI = *((short int *)par);
                        cli_app_log(CLI_LOG_INFO, "gsm rssi result is %d \n", *((short int *)par));
                    }
                    else if(device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_CDMA_SNIF_RSSI, &par, &par_len) != IF_APP_ERROR)
                    {
                        UPDATE_CDMA_RSSI = *((short int *)par);
                        cli_app_log(CLI_LOG_INFO, "cdma rssi result is %d \n", *((short int *)par));
                    }
                    else
                    {
                        strcpy((short int *)data, "");
                    }
                break;
                
                case CMD_WCDMA_EVT_SNIFF:
                case CMD_LTE_EVT_SNIFF:
                    ret |= cmd->cmdCode;
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SNIFFER_RESULT, &par, &par_len) != IF_APP_ERROR)
                    {
                        memcpy(&data[0], (I8 *)par, par_len);
                        ((I8 *)data)[par_len] = '\0';
                        cli_app_log(CLI_LOG_INFO, "sniffer result is %s \n", (I8 *)par);
                    }
                    else
                    {
                        strcpy((I8 *)data, "");
                    }
                    break;

                case CMD_CODE_BLACKLIST_ALERT:
                   {
                    PHONEINFO *phoneInfo = (PHONEINFO *)data;
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_TIMESTAMP, &par, &par_len) != IF_APP_ERROR)
                    {
                        phoneInfo->uptime = par[0];
                    }
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_DATAPROC_RECORD_IMSI, &par, &par_len) != IF_APP_ERROR)
                    {
                        memcpy(phoneInfo->imsi, (I8 *)par, par_len);
                        cli_app_log(CLI_LOG_INFO, "imsi %s \n", phoneInfo->imsi);
                    }
                    ret |= cmd->cmdCode;
                   }
                    break;

                case CMD_CODE_GPS_ALERT_INFO:
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_GPS_COORDINATE, &par, &par_len) != IF_APP_ERROR)
                    {
                        memcpy((I8 *)data, (I8 *)par, par_len);
                    }
                    ret |= cmd->cmdCode;
                    break;


                case CMD_EVT_ALARM_PA_SWR:
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_PA_ADDR, &par, &par_len) != IF_APP_ERROR) {
                        data[0] = *par;
                    }
//cli_app_log(CLI_LOG_WARNING, "pa %d swr warning  code %d  len %d \n", data[0], cmd->cmdCode, par_len);
					ret |= cmd->cmdCode;
                    cli_app_log(CLI_LOG_WARNING, "pa %d swr warning \n", data[0]);
                    break;

                case CMD_GSM_EVT_CONFIG:
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_GSM_WIRELESS_CONFIGURATION, &par, &par_len) != IF_APP_ERROR)
                    {
                        memcpy((I8 *)data, (I8 *)par, par_len);
                    }
                    ret |= cmd->cmdCode;
                    break;

                case CMD_EVT_EUTRAN_NMM_DELAY_REPORT:
					ret |= cmd->cmdCode;
					if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_UEID_IMSI, &par, &par_len) != IF_APP_ERROR) {
						memcpy(dreport->imsi, (I8 *)par, 15);

					}

					if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_NMM_DELAY, &par, &par_len) != IF_APP_ERROR){
						dreport->delay = *par;

					}
					if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_NMM_SINR, &par, &par_len) != IF_APP_ERROR){
						dreport->sinr = *par;

					}
					if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_UL_ARFCN, &par, &par_len) != IF_APP_ERROR){
						dreport->freq = *par;

					}
					if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_BBU_SLOT_ID, &par, &par_len) != IF_APP_ERROR){
						dreport->slotId = *par;

					}
					if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_RSRP, &par, &par_len) != IF_APP_ERROR){
						dreport->rsrp = *par;

					}
					if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_EUTRAN_PCI, &par, &par_len) != IF_APP_ERROR){
						dreport->pci = *par;

					}
					break;
                    

                case CMD_CDMA_EVT_NOT_RECV_IMSI:
                case CMD_GSM_EVT_NOT_RECV_IMSI:
                case CMD_WCDMA_EVT_NOT_RECV_IMSI:
                case CMD_TDSCDMA_EVT_NOT_RECV_IMSI:
                case CMD_GSM_EVT_NSYNC:
                case CMD_CDMA_EVT_NSYNC:
                case CMD_WCDMA_EVT_NSYNC:
                case CMD_TDSCDMA_EVT_NSYNC:
                case CMD_GSM_EVT_SYNC:
                case CMD_CDMA_EVT_SYNC:
                case CMD_WCDMA_EVT_SYNC:
                case CMD_TDSCDMA_EVT_SYNC:
                case CMD_EVT_ALARM_PA_OVER_POWER:
                case CMD_EVT_ALARM_PA_OVER_TEMP:
                case CMD_EVT_ALARM_PA_FAULT_PA:
                case CMD_EVT_ALARM_PA_FAULT_LNA:
                case CMD_EVT_ALARM_PM_GRAND_LOST:
                case CMD_EVT_ALARM_PM_DOOR_OPEN:
                case CMD_EVT_ALARM_SMS_TASK_DOWN:
                case CMD_CODE_SYSMONITOR_HEARTBEAT:
                case CMD_EVT_ALARM_PM_POWER_OFF:
                case CMD_EVT_ALARM_PM_POWER_ON:
                    ret |= cmd->cmdCode;
					break;
                }
            break;

        case DEV_OPCODE_SET:
            resp->id = cmd->cmdIndex;
            resp->dcode = cmd->cmdCode;
            ret = RESPONSE_IND_RESPONSE;

            switch (resp->dcode) 
            {
                case CMD_CODE_FEP_LOG_LEVEL:
                    
                    if (device_get_tlv(cmd->data, cmd->cmdLength,PARA_TYPE_MSG_FORWARD_MSG, &par, &par_len) != IF_APP_ERROR) 
                    {
                        memcpy(&data[0], par, par_len);
                        ret |= cmd->cmdCode;
                    } 
                    else 
                    {
		                ret = IF_APP_ERROR;
                    }
                    break;
#ifdef MODULE_TEST
               case CMD_CODE_SYSMONITOR_TEST_MODULE:
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYSMONITOR_TEST, &par, &par_len) != IF_APP_ERROR) 
                    {
                        memcpy(&data[0], par, par_len);
                        ret |= cmd->cmdCode;
                    } 
                    else 
                    {
		                ret = IF_APP_ERROR;
                    }
                    break;                                 
#endif
               case CMD_CODE_FEP_UPGRADE:
                   {
                    I8 *tmp_t = (I8 *)data;
                    memset(tmp_t, 0 ,DEV_INFO_ADD_LEN);
                    if(device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_UPGRADE_URL, &par, &par_len) != IF_APP_ERROR)
                    {
                       memcpy(tmp_t, par, par_len);
                       ret |= cmd->cmdCode;

                       tmp_t[par_len] = '\0';
                       cli_app_log(CLI_LOG_INFO, "url is %s \n", &data[0]);
                    }
                    if (device_get_tlv(cmd->data, cmd->cmdLength, PARA_TYPE_SYS_UPGRADE_MD5SUM, &par, &par_len) != IF_APP_ERROR)
                   {
                       memcpy(tmp_t + MD5_OFFSET, par, par_len);
                       tmp_t[MD5_OFFSET + par_len] = '\0';
                       cli_app_log(CLI_LOG_INFO, "md5sum is %s \n",tmp_t + MD5_OFFSET );
                       ret |= cmd->cmdCode;
                   }
                   }
                   break;

            }
            break;
    }
    return ret;
}


static void *device_msgrcv_thread(void *args)
{
    pthread_setname_np(pthread_self(), "msgrcv_thread");
    DEV_MSG *msg;
    I32 len;
    while (1) {
        msg = (DEV_MSG *) buffer_allocate();
        if (msg == NULL) {
            cli_app_log(CLI_LOG_CRITICAL,
                        "device_msgrcv_thread: allocate buffer failed \n");
            usleep(200000);
            continue;
        }
        setMsgRcvThreadOk();
        if ((len =  msgrcv(queue_rx, msg, DEVM_CMD_LENGTH, MSGQ_TYPE_INT, 0)) < 0) {
            cli_app_log(CLI_LOG_CRITICAL, "rcv bad msg, len is %d\n", len);
            buffer_free((I8 *) msg);
            usleep(200000);
            continue;
        }
        if (len == 0) {
            cli_app_log(CLI_LOG_CRITICAL, "rcv bad msg, len is %d\n", len);
            usleep(200000);
            continue;
        }

        cli_app_log(CLI_LOG_INFO, "<<<<<==========recv device msg from src=0x%04X len=%d===============\n", 
                    msg->hdr.srcID, msg->hdr.msgLength);
        buffer_dump_log((I8*)msg, msg->hdr.msgLength, CLI_LOG_DEFAULT);
        len -= sizeof(MSGHEADER);
        if (dev_sync_conf != DEV_SYNC_CONF_DONE) {
            event_queue_add(IF_APP_EVENT_SYNC_CONF, 0, len, (I8 *) & msg->cmd);
        } else if (dev_init_status != DEV_INIT_STAT_DONE) {
            event_queue_add(IF_APP_EVENT_INIT_DEV, 0, len, (I8 *) & msg->cmd);
        } else {
            event_queue_add(IF_APP_EVENT_DEVICE, 0, len, (I8 *) & msg->cmd);
        }
    }
    return NULL;
}

I32 device_interface_init(void)
{
    key_t key;

    key = ftok("/tmp", MSGQ_FTOK_ID);
    if (key == (key_t) - 1) {
        cli_app_log(CLI_LOG_CRITICAL,
					"ftok(%d) failed, %s\n", 
					MSGQ_FTOK_ID, strerror(errno));
        return -1;
    }
    queue_rx = msgget(key, IPC_CREAT);

    key = ftok("/tmp", MSGQ_FTOK_ID ^ 0xff);
    if (key == (key_t) - 1) {
        cli_app_log(CLI_LOG_CRITICAL,
					"ftok(%d) failed, %s\n", 
					MSGQ_FTOK_ID ^ 0xff, strerror(errno));
        return -1;
    }
    queue_tx = msgget(key, IPC_CREAT);

    if (pthread_create(&dev_rcv_thread, NULL, device_msgrcv_thread, NULL) != 0) {
        cli_app_log(CLI_LOG_CRITICAL,
                    "ERROR: Can't create device message receive thread\n");
        return -1;
    }
    return 0;
}

I32 device_interface__exit(void)
{
    pthread_cancel(dev_rcv_thread);
    pthread_join(dev_rcv_thread, NULL);
    return 0;
}

I8 *device_get_error_string(U32 id)
{
    I8 *ret = NULL;

    switch (id) {
            //warnings:
        case CMD_EVT_ALARM_PA_OVER_POWER:
            ret = warn_pa_over_pwr;
            break;

        case CMD_EVT_ALARM_PA_OVER_TEMP:
            ret = warn_pa_over_tmp;
            break;

        case CMD_EVT_ALARM_PA_SWR:
            ret = warn_pa_swr;
            break;
        case CMD_EVT_ALARM_PA_FAULT_PA:
        case CMD_EVT_ALARM_PA_FAULT_LNA:
            ret = warn_pa_fault;
            break;
        case CMD_GSM_EVT_NSYNC:
            ret = warn_gsm_fault;
            break;
        case CMD_GSM_EVT_SYNC:
            ret = warn_gsm_resume;
            break;

        case CMD_EVT_ALARM_PM_DOOR_OPEN:
            ret = warn_dev_door;
            break;
     
        case CMD_EVT_ALARM_PM_GRAND_LOST:
            ret = warn_dev_grand_lost;
            break;

            //errorcodes
        case PARA_TYPE_SNIFFER_BUSY:
            ret = sniffer_busy;
            break;
        case PARA_TYPE_EUTRAN_SNIFFER_EMPTY_RESULT:
            ret = sniffer_empty;
            break;
        case PARA_VALUE_ERROR_GSMBASEBAND_INACTIVE:
            ret = gsm_inactive;
            break;
        case PARA_VALUE_ERROR_PA_NOT_FOUND:
            ret = pa_not_found;
            break;
        case PARA_VALUE_ERROR_PA_OFF:
            ret = pa_inactive;
            break;

        case PARA_VALUE_ERROR_FW_ERR_DOWNLOAD:
            ret = warn_download_failed;
            break;

        case PARA_VALUE_ERROR_FW_ERR_MD5SUM:
            ret = warn_md5sum_mismatch;
            break;
  
        case PARA_VALUE_ERROR_FW_ERR_UPG_IN_PROGRESS:
            ret = warn_noclean;
            break;

        case PARA_VALUE_ERROR_FW_ERR_DECOMPRESS:
            ret = warn_decompross_failed;
            break;

        case PARA_VALUE_ERROR_FW_ERR_WRITE_KERNEL:
            ret = warn_write_kernel_failed;
            break;

        case PARA_VALUE_ERROR_FW_ERR_WRITE_ROOTFS:
            ret = warn_write_rootfs_failed;
            break;
        
        case PARA_VALUE_ERROR_FW_ERR_WRITE_X86APP:
            ret = warn_write_x86app_failed;
            break;

        case PARA_VALUE_ERROR_PA_PARAM:
        case PARA_VALUE_ERROR_INVALID_PARAMETERS:
        default:
            ret = gnrc_par_error;
            break;
    }
    return ret;
}
